→ Inheritance is the idea of accessing the data and the methods of its parent class.
→ Types of Inheritance :
- Single Inheritance
- Multi-level Inheritance
- Hierarchical Inheritance
- Multiple Inheritance (Not Support by JAVA, this is because if we consider 2 class B and C are extended (inherited) by A, both B and A has method display now when display method is invoked JVM gets confused, so to overcome this we can inherit 2 interfaces )
→ Its Mechanism is to bind data(variables) and methods into a single unit, the main advantage of encapsulation is DATA HIDING.
→ Data Hiding is nothing but the concepts giving permission to hide the inner classes and to give access to a particular code ( Getter’s and Setter’s ).
→ This concept is used to show needed required information to the user and the rest is hidden.
→This is used when a super-class is inherited by multiple sub-classes, here we don't want to implement methods which are common to all classes so we use abstract method for the rest of the methods which differs based on the subclasses.
→This reduces the duplicity of code.
→ by the word, Polymorphism means many-forms or behavior.
→ Two types of Polymorphism
- Run Time (Method Overriding)
→ when a class is inherited and if both super and sub-class have a same method then it corresponds to method overriding.
- Compile Time (Method Overloading)
→ Same function name with different parameters or with different datatype