- Abstraction
- Encapsulation
- Inheritance
- Polymorphism
1.Abstraction
Hiding internal
details and showing functionality is known as abstraction.
Example: phone
call, working of car
Advantages of Abstraction
1. Only show essential details to end user.
2. Hide complexity.
3. Security.
2.
Encapsulation
Binding (or
wrapping) code and data together into a single unit is known as encapsulation.Example: capsule
Advantages
of Encapsulation:
1. A read-only
(immutable) or write-only class can be made.
2. Control over
the data.
3. It helps in
achieving high cohesion and low coupling in the code.
3.Polymorphism
One task is
performed by different ways i.e. is known as polymorphism.
Example: God.
Types of polymorphism:
1. Static/compile
time polymorphism (by method overloading).
2. Dynamic/run
time polymorphism (by method overriding).
4. Inheritance
When one object
acquires all the properties and behaviors of parent object i.e. known as
inheritance.
Why inheritance is used?
1. Code
re-usability.
2. Run-time
polymorphism
Types of inheritance:
- Single inheritance
- Multilevel inheritance
- Hierarchical inheritance
- multiple inheritance
- Hybrid inheritance
No comments:
Post a Comment