OOPS Principles
1) Encapsulation
2) Abstraction
3) Inheritance
4) Polymorphism
Encapsulation
-> Encapsulation is used to combine attributes & methods as single entity / unit
-> Encapsulation provides data hiding
-> We can achieve encapsulation using Classes
class Demo {
//attributes
// methods
Abstraction
-> Abstraction means hiding un-necessary data and providing only required data
-> We can achieve Abstraction using interfaces & abstract classes
Ex : we will not bother about how laptop working internally
We will not bother about how car engine starting internally
Inheritance
-> Extending the properties from one class to another class is called as
Inheritance Ex: child will inherit the properties from parent
-> The main aim of inheritance is code re-usability
Note: In java, one child can't inherit properties from two parents at a time
Polymorphism
-> Exhibiting multiple behaviours based on situation is called as
Polymorphism Ex:-1 : in below scenario + symbol having 2 different
behaviours
10 + 20 ===> 30 (Here + is adding)
"hi" + "hello" ==> hihello (here + is concatinating)
Ex:-2:
When i come to class i will behave like a trainer
When i go to office i will behave like a employee
When i go to home i will behave like a family member