Lecture 2
Lecture 2
1
OUTLINE
Object-Oriented Paradigm
What is an Object?
What is a Class?
Constructing Objects from a class
Problem Solving in OO languages
More OO Concepts
Strength of Object-Oriented
Paradigm
2
Object-Oriented
Paradigm
To truly understand Java, we need to understand the paradigm on which it is built
on: the Object-Oriented Paradigm (OOP).
OOP is a more natural model compared to other models since OOP’s approach is
exactly the way humans view problem solving.
We take a closer look at the main ingredients of the model: Objects and Classes.
3
What is an Object?
An object is an individual, identifiable entity, either
real or abstract, that has a well-defined boundary.
An object has two main properties, namely:
• State: each object has attributes, whose values
represent its state.
• Behavior, each object has a set of behavior.
An example of a class is Student, an abstract entity that has attributes and a set of
behavior.
However, unless we have an actual student, we cannot say what the ID number is
or what the major is.
6
What is a Class?
(cont’d)
The following table shows further examples of
classes and their instances:
Classes Instances of (or Objects)
University UDU
Course CMP204
7
Constructing Objects from a Class
8
… Constructing Objects from a Class
Student thisStudent =
new Student(993546, “Suhaim Adil”,
3.5);
The relationship between the reference variable, thisStudent,
and the object created is shown by the following figure:
9
Problem Solving in OO languages
In the real world, problems are solved by interaction among
objects.
If you have a problem with your car, you take it to a mechanic for
repair.
10
Problem Solving in OO languages
To know the GPA of the student object we created, a message is sent as follows:
11
Strength of the OO Paradigm
12