Chapter 3 Inheritance and Polymorphism
Chapter 3 Inheritance and Polymorphism
(OOP Concepts)
Inheritance and
Polymorphism
10/23/2024 Prepared by: Melkamu D. 1
Encapsulation
• Encapsulation is a practice to bind related functionality
(Methods) & Data (Variables) in a protective wrapper
(Class) with required access modifiers (public, private,
default & protected) so that the code can be saved from
unauthorized access by outer world and can be made easy to
maintain.
• Encapsulation is the technique of making the fields in a
class private and providing access to the fields via public
methods.
• If a field is declared private, it cannot be accessed by anyone outside
the class, thereby hiding the fields within the class.
• When you have more than one method with the same
name but different arguments, the methods are said to
be overloaded.
}
} 10/23/2024 Prepared by: Melkamu D. 29
Cont…
• In the above example, there are four versions of add
methods. The first method takes two parameters
while the second one takes three.