google.com, pub-8786015629279405, DIRECT, f08c47fec0942fa0 Write a Program to Implement Multiple Inheritance in Java

Write a Program to Implement Multiple Inheritance in Java

0
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.

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


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Thank you for your interest 😊

We will back shortly after reviewing...

Thank you for your interest 😊

We will back shortly after reviewing...

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
To Top