Hybrid Inheritance is the combination of both Single and Multiple Inheritance. Again Hybrid inheritance is also not directly supported in Java only through interface we can achieve this. Flow diagram of the Hybrid inheritance will look like below. As you can ClassA will be acting as the Parent class for ClassB & ClassC and ClassB & ClassC will be acting asParent for ClassD.
Example
interface A { public void methodA(); } interface B extends A { public void methodB(); } interface C extends A { public void methodC(); } class D implements B, C { public void methodA() { System.out.println("MethodA"); } public void methodB() { System.out.println("MethodB"); } public void methodC() { System.out.println("MethodC"); } public static void main(String args[]) { D obj1= new D(); obj1.methodA(); obj1.methodB(); obj1.methodC(); } }
Output:
MethodA MethodB MethodC
No comments:
Post a Comment