Inheritance means child class can acquire all the properties and attributes from base class. In java multiple inheritance we inherit the new derived classes form one base class. Multiple inheritance in java example contains one base class and we extend base class to derive new child classes from it. After java multiple inheritance the derived classes can acquire the all the properties and attributes.
The following example of multiple inheritance in java shows how child classes are derived from base class using java multiple inheritance.
Simple code for java multiple inheritance
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
class Base // Starts program of multiple inheritance in java { void get() { System.out.println("This is Base class"); } } class Derived extends Base { void set() { System.out.println("This is Derived-1 class"); } } class MultipleInheritance extends Derived // Derived class of java multiple inheritance { void met() { System.out.println("This is Derived-2 class"); } public static void main(String args[]) { MultipleInheritance obj=new MultipleInheritance(); // will call all methods explicitly obj.get(); obj.set(); obj.met(); } } // End of multiple inheritance in java example |
Output of multiple inheritance in java example