Inheritance in Java

Overview

Inheritance is a concept of inheriting methods and properties of another class.

Type of Inheritance

  1. Single Inheritance
    Class A->B: B extends A
  2. Multilevel Inheritance
    Class A->B->C: C extends B and B extends A
  3. Hierarchical Inheritance
    Class A->B->C->D: D, C and B extends A
  4. Multiple Inheritance
    Class A->B->C: C extends A and B
  5. Hybrid Inheritance
    Class A->B->C->D: D extends B and C which are a subclass of A.

What we can do in Subclass?

  1. Subclass can use the inherited properties just like it's own property.
  2. Subclass can declare those new properties which are not declared in superclass.
  3. Subclass can use the inherited methods just like it's own methods.
  4. Subclass can declare those new methods which are not declared in superclass.
  5. You can write a constructor in subclass which can call the constructor of a superclass either implicitly or by using the super keyword
  6. You can write the same static method in subclass which is declared in superclass, thus by hiding it.

Reference



Comments

Popular posts from this blog

Collections in Java

Exception Handling

OOPS Concept in Java