DEV Community

Hayes vincent
Hayes vincent

Posted on

Day in paiyligam(Inheritance)

Today topic inheritance

Types of Inheritance :

Single Inheritance: A class inherits from only one superclass

**Multilevel Inheritance: **A class inherits from a class that itself inherits from another class, forming a chain

Hierarchical Inheritance: Multiple subclasses inherit from a single superclass.

*My first program in single inheritance: *

My own try program is success fully run happy to shares this,

This my parent class in my progrom :

class Parent{
void GetName(){
System.out.println("Father name: muthu");
}
public static void main(String args[]){
}
}

This my child class my class program:

class Son extends Parent{
void GetSon(){
System.out.println("Son name is:kala");
}
public static void main(String args[]){
Son obj=new Son();
obj.GetName();
obj.GetSon();
}
}

Multilevel inheritance program my try:

Multilevel inheritance is a type of inheritance in Java where a class is derived from a class that is also derived from another class. In other words, it forms a chain of inheritance.

My try :
**
**This parent calss of the program,

class Cengovt{
void GetCentral(){
System.out.println("Central goverment:Wishing you and the people of your state a very Happy Independence Day");
}
public static void main(String args[]){
}
}

The child calss of program,

class Stategvt extends Cengovt{
void GetState(){
System.out.println("State Goverment:Happy Independence Day to my pepole");
}
public static void main(String args[]){
}
}

*The another child class in program
*

class Govt extends Stategvt{
void GetGovt(){
System.out.println("TO all wishes to my pepole");
}
public static void main(String args[]){

Govt obj=new Govt();
obj.GetGovt();
obj.GetCentral();
obj.GetState();

}
}

Hierarchical Inheritance

Hierarchical Inheritance is a type of inheritance where multiple subclasses inherit from a single parent class

*My Hierarchical program:
*

The parent class in Hierarchical program,

class Vehicle{
void GetVeh(){
System.out.println("My vehicle name is:");
}
public static void main(String args[]){
}
}

And another child class in Hierarchical,

class Bike extends Vehicle{
void BikeName(){
System.out.println("My bike name is Plusar");
}
public static void main(String args[]){
}
}

And the another child class ,

class Car extends Vehicle{
void GetCar(){
System.out.println("My car name is BMW");
}
public static void main(String args[]){
Car obj=new Car();
Bike obje=new Bike();
obj.GetVeh();
obje.BikeName();
obj.GetCar();
}
}

Output of the program

Top comments (0)