OOPs Concepts in JAVA - Inheritanace


OOPS, JAVA, Inheritanceinjava




OOPs -
Ojbect Oreiented Programming Concepts 

Inheritance

Child class acquiring the properties of the parents class is called INHERITANCE

We use Extends keyword for inheritance

Example >

Class A {

Static Int a (2); 
Static int b (3);

}

As class A has two integer values a =2 and b =3 and we want to use these values in different class, instead of creating these values each time for different classes we can just inheritate (acquired) these properties in the another class 

Class B  extends A{

Here we get the value for class A in class B by Inheritance 

}

Types of Inheritance

  • Single
  • Multiple
  • Multilevel
  • Hierarchical

Single Inheritance

Single Parent Single Child

Class A {


}

Class B extends Class A{


}


Multiple Inheritance (Not possible as per JAVA rules)

Multiple Parent and Single Child


Class A {


}

Class B {


}

Class C extends Class A {


}

Class C Extends B {


}


Multilevel Inheritance

Parent, Child and GrandChild

Class A {


}

Class B extends A {


}

Class C Extends B {


}


Hierarchical Inheritance

One Parent multiple Child


Class A {


}

Class B  extends A{


}

Class C extends A{


}



 





Comments