Multiple Inheritance using Interfaces

MULTIPLE INHERITANCE

Multiple Inheritance is nothing but one class extending morethan one class. Multiple Inheritance is basically not supported by many Object Oriented Programming languages such asJava, Small Talk, C# etc.. (C++ Supports Multiple Inheritance). As the Child class has to manage the dependency of more than one Parent class. But you can achieve multiple inheritance in Java using Interfaces.

Multiple_Inheritance_in_Java

Multiple inheritance in Java by interface

If a class implements multiple interfaces, or an interface extends multiple interfaces i.e. known as multiple inheritance.
 multiple inheritance in java
  1. interface Printable{  
  2. void print();  
  3. }  
  4.   
  5. interface Showable{  
  6. void show();  
  7. }  
  8.   
  9. class A7 implements Printable,Showable{  
  10.   
  11. public void print(){System.out.println("Hello");}  
  12. public void show(){System.out.println("Welcome");}  
  13.   
  14. public static void main(String args[]){  
  15. A7 obj = new A7();  
  16. obj.print();  
  17. obj.show();  
  18.  }  
  19. }  
Output:Hello
       Welcome

No comments:

Post a Comment