Java Inheritance

                                    Inheritance


Using the things in one class of the program we are making in another class.

Example: Old and New phone👇




After inherit 👇



Types Of Inheritance


1)Single Inheritance

2)Multilevel Inheritance

3)Hierarchical Inheritance






Single Inheritance

  • Things in one class are used in another class.

  • Here class B has Inherited from class A.
  • class A  operates as a "Superclass" and class B as a "Subclass". 

  • class B can use the "Variables" and "Methods" of class A 


    Multilevel Inheritance

  • There are Three classes here.

  • class A  works as a"Superclass" and class B and class C  as a "Subclass". 

  • And when class C  works as a "Subclass"class B works as a "Superclass".

  • class B can use  the"Variables" and "Methods" of class A

  • class C can use the "Variables" and "Methods" of class B

  • class C can use the "Variables" and "Methods" of class A
    (Because class B is Inherited from class A)


Hierachicle Inheritance

  •  class A  works as a "Superclass" and class B and class C  as a "Subclass". 

  •  class B can use the "Variables" and "Methods" of class A

  • class C can use the "Variables" and "Methods" of class A

    Comments

    Popular posts from this blog

    Java Method Overriding

    Java Polymorphism