Ticker

6/recent/ticker-posts

Inheritance in Java Programming

Inheritance 

It’s a mechanism where the child class acquires the properties of the parent class or supper class.

java supports inheritance there are many types of in heritance 

  • single inheritance ( above example ) 
  • multilevel inheritance 
  • hierarchical inheritance

Example for multilevel inheritance 

class Parent 

class Boy extends Parent 

class Girl extends Boy 

{

}

In the above example the Boy class can acquire the properties of Parent class, mean while has Girl class extends Boy class, so a Girl class can acquire the properties of both the Parent class and the Boy class. 

multilevel inheritance

Example for hierarchical inheritance

hierarchical inheritance

Note : Java does not support the multiple inheritance where has it only supports multilevel inheritance. 

Not support Multiple inheritance java

If class A and class B have same methods than the class C will be in confusion to take the method from which class so this concept was ruled out in java. 

If you create the Object of class C than the constructor is called, hear that constructor will execute the super statement, here again there is a confusion which is parent class and whose constructor is need to be called

ALSO SEARCH:

"polymorphism in java"

"what is inheritance in java"

"types of inheritance in java"

"inheritance in java with realtime example"

"multiple inheritance in java"

"single inheritance in java program with output"

"hybrid inheritance in java"

"what is inheritance in java"

"inheritance in java with example programs"