Multilevel Inheritances in Java Program
Multilevel inheritances in Java
In Multilevel inheritances there exists single base class, single derived class and multiple intermediate base classes.
Single base class + single derived class + multiple intermediate base classes.
Intermediate base classes
An intermediate base class is one in one context with access derived class and in another context same class access base class.
class Car
{
public void Car()
{
System.out.println("Class Car");
}
}
class Maruti extends Car
{
public void Maruti()
{
System.out.println("Class Maruti");
}
public void brand()
{
System.out.println("Brand: Maruti");
}
}
public class Inherit extends Maruti
{
public void speed()
{
System.out.println("Max: 80Kmph");
}
public static void main(String args[])
{
Inherit obj=new Inherit();
obj.brand();
obj.speed();
obj.Car();
obj.Maruti();
}
}
Can you give me out put sir
ReplyDeleteBrand: Maruti
ReplyDeleteMax: 80Kmph
Class Car
Class Maruti