multiple inheritance example in java

java also supports the multiple inheritance in which the methods or variable of parent class are inherited more then one class here is the example code and output for the Multiple Inheritance

class Mobile {
public void MobileMethod() {
System.out.println(“I am Mobile class and I am a parent”);
}
}

class Android extends Mobile {
public void AndroidMethod() {
System.out.println(“I am Android class and I am a Child of Mobile class”);
}
}
class iphone extends Mobile {
public void iphoneMethod() {
System.out.println(“I am iphone class and I am a Child of Mobile class”);
}
}
public class MultipleInheritanceExample {

public static void main(String[] args) {
// Create the parent calss object and called the parent method
Mobile objMobile = new Mobile();
objMobile.MobileMethod();

// Create the Android child calss object and called the child method
Android objAnroid = new Android();
objAnroid.AndroidMethod();

// Create the iphone child calss object and called the child method
iphone objiphone = new iphone();
objiphone.iphoneMethod();

// Called the parent method using child class object
objAnroid.MobileMethod();
objiphone.MobileMethod();
}
}

Output

I am Mobile class and I am a parent
I am Android class and I am a Child of Mobile class
I am iphone class and I am a Child of Mobile class
I am Mobile class and I am a parent
I am Mobile class and I am a parent