O GoConqr está de visual novo! Conte para nós o que você achou.

Mapa mental

Java Objects

Jean luc Choiseul Inglês

Conteúdo do mapa

Java Objects

  1. They all can have 2 features

    • Attributes/Fields
      • A car has attributes
        • color
        • # of tires
        • plate #
    • Actions/Methods
      • A car has methods too
        • accelerate
        • Steer
        • brake
    • Both are optional
  2. Java Class: blueprint required to create an object

    • template/cookie cutter used to create objects of the same type
    • Allow people to create abstraction of a problem
      • abstraction = using programming objects to represent real world objects
      • Abstraction only includes details of a real world object that are relevant
    • "Employee" Class creates any number of Employee objects with different values plugged into fields and methods
      • Assume class has fields for age, position, and salary
        • all employees must have an age
        • all employees must have a position
        • all employees must have a salary
    • Class definition
      • 3 features of a class
        • class name
          • class names capitalize the initial of each word
            • PostOffice instead of Postoffice, postOffice, or postoffice
        • Fields
          • They're variable
          • can be primitive or references to objects
            • "Employee class may have "address" as a field of type "Address", which is a class that represents a street address
            • Object A can contain object B if object A's class has variables that reference to object B
          • field names follow "camel" convention
            • maxAge
            • address
            • numberOfRows
        • Methods
          • Define actions that a class's objects can do
          • methods have 2 parts
            • Declaration
              • has a return value, the method name, and a list of arguments
                • commas used to separate more than 1 argument
              • ex: returnType methodName (listOfArguments)
                • returnTypes:
                  • primitives
                  • objects
                  • void
                    • keyword for when a method isn't supposed to output anything
                • getAddress returns an "Address" object ex: Address getAddress()
            • Body
              • contains code that performs the action
      • Class declaration: must use keyword "class" followed by desired class name, a class has a body within braces
        • class ClassName { [class body] }
      • Must be saved in a file with same name as ClassName with java extension
        • Employee class = Employee.java
    • Method Main
      • special method that provides entry into application
      • only 1 class in an app needs the main method, which allows the class containing it to be invoked
      • ex: public static void main (String [ ] args)
    • Constructors
      • every class needs at least 1 constructor so it can create objects
      • A constructor looks like a method but isn't one because it doesn't return a value and doesn't use void
      • constructor must have the same name as the class
        • ex: constructorName (list of inputs) { [constructor body] }
      • constructors may not have inputs/arguments
      • constructor arguments can be used to initialize the fields in the object
        • like default settings/state

Informações

Descrição
Mapa Mental sobre Java Objects, criado por Jean luc Choiseul em 08-09-2019.
Visualizações
0
Avaliação

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?