Lecture 4
Lecture 4
SOFTWARE
DEVELOPMENT
~ THARUKA PERERA
Lecture 04
Foundation Certificate in IT – UOB Batch
CLASSES AND OBJECTS
What Is a Class?
Usage of constructor
CAR?
WHAT IS A CLASS?
common characteristics.
•Drive() , Reverse(), Speed(),
Functions
Simply a class is a blueprint that Break()
void drive();
void speed();
}
WHAT IS AN OBJECT?
When a program is executed, the objects interact by sending messages to one another
Objects exhibit:
Identity: Objects are distinguishable from one another
Behaviour: Objects can perform tasks
State: Objects store information
OBJECTS
An object is created in the memory using the keyword ’new’ and is referenced by an identifier called a "reference".
Rectangle Class
Rect2 Object
Purpose of a constructor is to assign values to
the instance variables at the runtime.
}
}
PARAMETERIZED CONSTRUCTOR.
Purpose of a constructor is
public class Car {
to assign values to the
int modelYear; instance variables at the
runtime
String modelName;