Classes and Objects: Java Is Strictly An Object-Oriented Programming Language. Java Code Class Interface
Classes and Objects: Java Is Strictly An Object-Oriented Programming Language. Java Code Class Interface
Classes
Describe the objects attributes behaviors
Procedural Programming
Flowcharts Decomposition Procedures
Object-Oriented Programming
Classes Objects Inheritance Encapsulation Polymorphism
Payroll Program
Determining objects in problem Employees Company Payroll department more objects.
Employee Class
Attributes name address national id number Behaviors hours worked() pay()
Employee class
public class Employee { public String name; public String address; public String id; public double hPay; }
public class Employee { public String name; public String address; public String id; public double hPay; public void writeDetails { System.out.println(name + + id); } }
public class Employee { public String name; public String address; public String id; public double hPay; public double computePay { return hPay * 40; } }
Dot operator
jeep.fCap = 16;
Instantiating an Object
Vehicle jeep ;
Constructor
Initializes an object when its created. Has the same name as its class. Syntactically similar to a method. Has no explicit return type.
Constructor
All classes have constructors. Java automatically defines default constructor that initializes all member variables to zero.
Garbage Collection
j1
j2
Vehicle j3 = j2;
j3
j1
j2
Vehicle j3 = j2;
j3
j1 = j2;