3. Encapsulation
• The wrapping up of data and methods into a single
unit is known as Encapsulation
• The data is not accessible to the outside world and
only those methods, which are wrapped in the
class can access it
• The insulation of the data from direct access by
the program is called “ Data Hiding”
3
4. Inheritance
• Inheritance is the process by which objects of one
class acquire the properties of objects of another
class
• Inheritance provides the idea of reusability
• We can add additional features to an existing class
without modifying it
• The original class is called as base class
• The inherited classes are called as sub classes
4
5. Inheritance
Shape
Circle Rectangle Triangle
Fig. 4.3 Inheritance
5
6. Inheritance
• In the Fig. 4.3 Shape is the base class
• Circle, Rectangle and Triangle are classes
that are inherited
6
7. Polymorphism
• Polymorphism is another feature of OOP concept
• ‟Poly‟ means „many‟, ‟Morph‟ means „forms‟
• “Polymorphism means the ability to take more
than one form”
7
8. Polymorphism
• Allows a method to have multiple
implementations that are selected based on which
type of object is passed
8
9. Polymorphism
•Current object is circle
• method draw() is called
Shape
draw()
Circle Rectangle Triangle
draw() draw() draw()
Fig. 4.4 Polymorphism
9
10. Polymorphism
•Current object is Triangle
•Method draw() is called
Shape
draw()
Circle Rectangle Triangle
draw() draw() draw()
Fig. 4.5 Polymorphism
10