Mind map
Objects and Classes
Map content
Objects and Classes
Every object can have fields(attributes) and/or methods(actions).
Class: Blueprint for the object
- Needs: Class name, fields, methods
- Class declaration: must use keyword class
- {} are used after class for the body
- Every class must have at least one constructor
- Looks like a method
- Does not have a return value
- Must have same name as class
- constructorName (listofArguments) { [constructor body] }
- Used to initialize fields in object
- new Employee(20, 90000.00);
- public className (int arg1, method arg 2)
- Used to initialize fields in object
- Class declaration: must use keyword class
- Class definition must be saved in file with same name as class name with .java
- Needs: Class name, fields, methods
Fields are variables for the class in question
- Fields can refer to another object as well
- Follow camel naming convention (add,dataType,etc.)
- Fields can refer to another object as well
Methods define actions of a object
- returnType methodName (listofArguments)
- double getSalary() returns a double with no accepting arguments
- int add(int a, int b) accepts two arguments and adds them
- Main provides entry point to an application
- One of the classes in an application needs to have a main method
- public static void main(String[] args)
- Can pass arguments to main when using java to run a class
- java className arg1 arg2 arg3...
- One of the classes in an application needs to have a main method
- returnType methodName (listofArguments)
Assign created object to an object reference variable
- objectReference.methodName
- objectReference.fieldName
- When reference variable does not have value, it has a null value
- If (book == null){ book = new Book(); }
Information
- Description
- Mind Map on Objects and Classes, created by Kevin Benitez on 20/05/2021.
- Created by
- Kevin Benitez
- Views
- 0
- Rating