Thursday, 12 February 2015

Interface Abstarct class In java

  1. interface A{  
  2. void a();//bydefault, public and abstract  
  3. void b();  
  4. void c();  
  5. void d();  
  6. }  
  7.   
  8. //Creating abstract class that provides the implementation of one method of A interface  
  9. abstract class B implements A{  
  10. public void c(){System.out.println("I am C");}  
  11. }  
  12.   
  13. //Creating subclass of abstract class, now we need to provide the implementation of rest of the methods  
  14. class M extends B{  
  15. public void a(){System.out.println("I am a");}  
  16. public void b(){System.out.println("I am b");}  
  17. public void d(){System.out.println("I am d");}  
  18. }  
  19.   
  20. //Creating a test class that calls the methods of A interface  
  21. class Test5{  
  22. public static void main(String args[]){  
  23. A a=new M();  
  24. a.a();  
  25. a.b();  
  26. a.c();  
  27. a.d();  
  28. }} 

No comments:

Post a Comment