Chapter 1
Chapter 1
In real life, things that you see such as cars, trees, cats,
mobile phones and so on are objects. Even, you as a
student is an object.
Behaviour
Attribute/State Identity
Example 1: car
◦ Start engine
◦ Speeding
◦ Change gear
◦ Stop
Example 2: dog
◦ Barking
◦ Fetching
Behaviours:
• playing, fighting, hunting
Cat Cat2:
Attribute:
• Colour: black
• EyeColour: green
• WeightKg: 3.5
Behaviours:
• playing, fighting, hunting
More examples..
Attribute/state:
• Colour: white
• Manufacturer: Nissan
• Model: Grand Livina
• Type: MPV
Car
Behaviours :
• Moving, speeding
Exercise 1
the object
The class that contains the main method of a Java
class
Class (cont..)
STUDENT
Variables
stuID – represent the data/attributes
stuName - set of properties
stuProg
setID() Methods
setName() – represent the behaviors
setProg() - a sequence of instructions that class or
object needs to follow
Object
:STUDENT
a) Rectangle
b) Book
c) Employee
d) Fee
Exercise 2
Easier debugging
◦ classes can be tested independently
◦ reused objects have already been tested
Characteristics / concepts of OOP
Abstraction
Encapsulation
Inheritance
Polymorphism
Abstraction
Abstraction ~ designing classes
Example 1:
Driving a car
When you drive a car, you don’t have to know how the
gasoline and air are mixed.
Instead you only have to know how to use the controls.
Example 2:
ATM Machine
People can perform ATM operations like cash withrawal,
Example:
// renders Square
public void render() {
System.out.println("Rendering Square...");
}
}
// renders circle
public void render() {
System.out.println("Rendering Circle...");
}
}
class Main {
public static void main(String[] args) {