You are on page 1of 2

Lesson 2

Principles of OOP:
1. Data Abstraction – It is defined as an act of representing the essential
features without including the background details.
Eg: Consider a real life example of a man driving a car. The man only knows that
pressing the accelerators will increase the speed of car or applying brakes will
stop the car but he does not know about how on pressing accelerator the speed is
actually increasing, he does not know about the inner mechanism of the car or
the implementation of accelerator, brakes etc in the car.

2. Encapsulation – Wrapping up of data and its associated functions into a


single unit.
Eg: School bag is one of the most real examples of Encapsulation. School bag
can keep our books, pens, etc.
In java Encapsulation is implemented through “class”.

Note: Details about class will be discussed in the next lesson.


(Lesson 2 Continued…)

3. Inheritance – It is the property by virtue of which one class acquires the


property of another class. The class which inherits is called the derived class
and from which it inherits is called the base class. It promotes reusability.
Eg: The real life example of inheritance is child and parents, the physical
properties of father and mother are inherited by his son or daughter. Here son or
daughter is the derived class and father or mother is the base class.

4. Polymorphism – It is the ability to represent an object in more than one


form or the ability of a function to perform different tasks.
Eg: Consider the function area which can calculate the area of different
geometrical figure like square, circle, triangle, rectangle, triangle, etc.

Area of
Square

Area of Area of
Triangle Area Circle

Area of
Rectangle

Test your Skills:


Q1. Define the following term with one example:
a) Encapsulation b) Polymorphism c) Data Abstraction d) Inheritance

You might also like