Inheritance in Java
Overview
Inheritance is a concept of inheriting methods and properties of another class.
Type of Inheritance
- Single Inheritance
Class A->B: B extends A - Multilevel Inheritance
Class A->B->C: C extends B and B extends A - Hierarchical Inheritance
Class A->B->C->D: D, C and B extends A - Multiple Inheritance
Class A->B->C: C extends A and B - Hybrid Inheritance
Class A->B->C->D: D extends B and C which are a subclass of A.
What we can do in Subclass?
- Subclass can use the inherited properties just like it's own property.
- Subclass can declare those new properties which are not declared in superclass.
- Subclass can use the inherited methods just like it's own methods.
- Subclass can declare those new methods which are not declared in superclass.
- You can write a constructor in subclass which can call the constructor of a superclass either implicitly or by using the super keyword
- You can write the same static method in subclass which is declared in superclass, thus by hiding it.
Comments
Post a Comment