Mindmap
Object-Oriented Programming Objects and Classes

Inhalt der Mindmap
Object-Oriented Programming Objects and Classes
Object/Instance
- Both fields and methods are optional for Java objects.
- Attributes / Field (Java) car example
- color
- number of tires
- plate number
- number of values
- plate number
- number of tires
- color
- Actions / Methods (Java) car example
- run
- brake
- run
- Most common way to create object is new keyword. new is followed by constructor of class
- new Employee;
- Want to assign object to an object variable to manipulate later
- ObjectName Object reference = new Object()
- Employee employee = new Employee()
- can call its methods and fields but using a period (.)
- objectReference.methodName objectReference.fieldName
- can call its methods and fields but using a period (.)
- Employee employee = new Employee()
- ObjectName Object reference = new Object()
- Want to assign object to an object variable to manipulate later
- new Employee;
- Attributes / Field (Java) car example
- Classes
- A class determines what object you get. It is a template used to create OBJECTS of identical type
- All program elements in Java must reside in a class
- Class Name
- class file name must have a java extension
- class className { [class body] }
- class Employee { int age; double salary; }
- class className { [class body] }
- Pascal naming convention used. where the initial of each word is capitalized
- class file name must have a java extension
- Fields
- Camel naming convention used, where the initial of each word is capitalized except the first word
- Can be primitive of references to objects. Can also refer to another object. (object can contain other objects)
- Employees may have address field of type Address which is a class
- Address address;
- Null reference variable
- A reference variable of an object that does not have a value
- if you declare a local reference within a method but assign it no object, need to assign null
- Book book = null;
- if you declare a local reference within a method but assign it no object, need to assign null
- A reference variable of an object that does not have a value
- Employees may have address field of type Address which is a class
- Methods
- Camel naming convention used, where the initial of each word is capitalized except the first word
- Define actions that a class's objects can do
- declaration / signature
- consists of a return value, method name, and list of arguments
- return can be primitive, object, or void.
- void means method returns nothing
- return can be primitive, object, or void.
- consists of a return value, method name, and list of arguments
- body
- contains code to preform the action
- returnType methodName (list of arguements)
- if method take more than one argument: int add ( int a, int b)
- declaration / signature
- The Method Main
- provides entry point to an application that consists of multiple classes. only on class needs to have main method.
- public static void main ( String [] args)
- can pass arguments to main to run a class
- java className arg1 arg2 arg 3 ...
- can pass arguments to main to run a class
- public static void main ( String [] args)
- provides entry point to an application that consists of multiple classes. only on class needs to have main method.
- Class Name
- All program elements in Java must reside in a class
- Constructors
- Every class must have at least one constructor. Looks like a method but does not have a return value.
- Must have same name as the class
- looking at the elements of a method, a constructor may have zero argument which is called nonarguement
- constructorName (listOfArguments) { [constructor body] }
- with second constrictor can pass values at same time to create object
- new Employee (20, 90000.00)
- with second constrictor can pass values at same time to create object
- Every class must have at least one constructor. Looks like a method but does not have a return value.
- UML Class diagram example with 5 fields and one method.
- field and type separated by :
- method's arguments in parentheses and return is written after :
- field and type separated by :
- A class determines what object you get. It is a template used to create OBJECTS of identical type
- Both fields and methods are optional for Java objects.
Bilder und Dateien der Mindmap
Informationen
- Beschreibung
- Mindmap am Object-Oriented Programming Objects and Classes, erstellt von Amanda Dischinger am 25/05/2020.
- Erstellt von
- Amanda Dischinger
- Aufrufe
- 0
- Bewertung
