Friday, July 28, 2017

OOPS Principles


  1.     Abstraction
  2.     Encapsulation
  3.     Inheritance
  4.     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:
  1.     Single inheritance
  2.     Multilevel inheritance
  3.     Hierarchical inheritance
  4.     multiple inheritance
  5.     Hybrid inheritance

No comments:

Post a Comment