Mindmap
Java Objects
Inhalt der Mindmap
Java Objects
They all can have 2 features
- Attributes/Fields
- A car has attributes
- color
- # of tires
- plate #
- A car has attributes
- Actions/Methods
- A car has methods too
- accelerate
- Steer
- brake
- A car has methods too
- Both are optional
- Attributes/Fields
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
- Assume class has fields for age, position, and 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
- class names capitalize the initial of each word
- 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()
- returnTypes:
- has a return value, the method name, and a list of arguments
- Body
- contains code that performs the action
- Declaration
- class name
- 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
- 3 features of a class
- 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
Informationen
- Beschreibung
- Mindmap am Java Objects, erstellt von Jean luc Choiseul am 08/09/2019.
- Erstellt von
- Jean luc Choiseul
- Aufrufe
- 0
- Bewertung