DEV Community

nantha kumar
nantha kumar

Posted on

Inheritance

What is Inheritance :

  1. Child object behaving as a parent object.

How to Achive Inheritance :

  1. To achive inheritance, we should use extends keyword.

Types of inheritance :

  1. Single Inheritance
  2. Multilevel Inheritance
  3. Hierarchical Inheritance
  4. Hybrid Inheritance
  5. Multiple Inheritance

Single Inheritance :

  1. One child class inherits from one parent class.

Multilevel Inheritance :

  1. A class inherits from another class, and then another class inherits from that class. Example : Grandparent → Parent → Child

Hierarchical Inheritance :

  1. Multiple child classes inherit from a single parent class.

Hybrid Inheritance :

  1. Combination of two or more types of inheritance.

Multiple Inheritance :

  1. if we use multiple inheritance, ambiquity problem will occure.

  2. So Java does not support multiple inheritance. but it supports it via interfaces.

Top comments (0)