Multiple Inheritance allows a class to have more than one super class and to inherit features from all parent class. it is achieved using interface. This is possible only by using interface in java.
Here a example of Multiple Inheritance.
Here a example of Multiple Inheritance.
Syntax
public interface A{
//Do Something
}
public interface B extends A{
//Do Something
}
public interface C extends A{
//Do Something
}
Multiple Inheritance Using Interface Example Program
interface vehicleone{
int speed=90;
public void distance();
}
interface vehicletwo{
int distance=100;
public void speed();
}
class Vehicle implements vehicleone,vehicletwo{
public void distance(){
int distance=speed*100;
System.out.println("distance travelled is "+distance);
}
public void speed(){
int speed=distance/100;
}
}
class MultipleInheritanceUsingInterface{
public static void main(String args[]){
System.out.println("Vehicle");
obj.distance();
obj.speed();
}
}
Sample Output
Output is:
distance travelled is 9000