Inheritance in Java OOPs with Example (JNNC Technologies)



What is Inheritance?

Inheritance is a mechanism in which one class acquires the property of another class. For example, a child inherits the traits of his/her parents. With inheritance, we can reuse the fields and methods of the existing class. Hence, inheritance facilitates Reusability and is an important concept of OOPs.

Types of Inheritance

There are Various types of inheritance in Java:
  1. Single Inheritance:
  2. In Single Inheritance one class extends another class (one class only).
      Types of Inheritance
      In above diagram, Class B extends only Class A. Class A is a super class and Class B is a Sub-class.
    1. Multiple Inheritance:
    2. In Multiple Inheritance, one class extending more than one class. Java does not support multiple inheritance.
      Types of Inheritance
      As per above diagram, Class C extends Class A and Class B both.
    3. Multilevel Inheritance:
    4. In Multilevel Inheritance, one class can inherit from a derived class. Hence, the derived class becomes the base class for the new class.
      Types of Inheritance
      As per shown in diagram Class C is subclass of B and B is a of subclass Class A.

Post a Comment

0 Comments

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();