Inheritance:

there are five types of inheritance:

  • Single-level inheritance.
  • Multi-level Inheritance.
  • Hierarchical Inheritance.
  • Multiple Inheritance.
  • Hybrid Inheritance.

single Inheritance:

Single inheritance is the simplest type of inheritance in java. In this, a class inherits the properties from a single class. The class which inherits is called the derived class or child class or subclass, while the class from which the derived class inherits is called the base class or superclass or parent class.

reference id:

The multi-level inheritance includes the involvement of at least two or more than two classes. One class inherits the features from a parent class and the newly created sub-class becomes the base class for another new class.

reference id:

Program:

class Hplaptop{
String keylang;
boolean keyLight;
boolean isTouchDisp;
/public Hplaptop(String klang, boolean klight, boolean isTouch ){ keylang = klang; keylight = klight; isTouchDisk = isTouch; }/
void watchingMovie(){
System.out.println(“watching movie”);
}
}

class HpABC extends Hplaptop{
String mname;
void coding(){
System.out.println(“coding”);
}
}

class Hpcse extends HpABC{
String modelname;
void playingGame(){
System.out.println(“playing Game”);
}
public static void main(String args[])
{
Hpcse c=new Hpcse();
c.coding();
c.watchingMovie();
c.playingGame();
}
}

output:

coding

watchingMovie

playingGame

,

Leave a comment

Design a site like this with WordPress.com
Get started