How to access multiple interface method in base class





This     is   simple   tricky   way to get  methods  of  interface  in the  subclass . This  is
 simple but  frequently asked question in java  interviews. Here   it  is  important to see
 that , only that class or interface method will  going to be call  whose  object created.






 interface It{
public void print();
 }

  interface Ite{
 
  public void  print();
 
  }

  class  AC{
 
  public void print(){
 
  System.out.println("I am in A");
  }
  }

  class  AB extends AC{
 
public void print(){

System.out.println("i am in B");
 }
   }

public class javaexpinf extends AB implements It , Ite {



public void print(){
        
         System.out.println("Print Main");
        
         }


public static void main(String[] args) {
// TODO Auto-generated method stub

    javaexpinf  ig=new   javaexpinf();
   
               ig.print();
             
               System.out.println(ig.hashCode());
                                 
               AB  b=new   javaexpinf();
             
                 b.print();
               
               AC pf=new   javaexpinf();
             
                                   pf.print();
             
                AC  bg=new AB();
               
                                     bg.print();
            
                AB n=new AB();
                 n.print();
               
                AC  ac=new  AC();
             
                ac.print();
               
               
}

}


Program   Output:
Print Main
705927765
Print Main
Print Main
i am in B
i am in B
I am in A
How to access multiple interface method in base class How to access multiple interface method in base class Reviewed by Mukesh Jha on 9:39 AM Rating: 5

No comments:

Add your comment

All Right Reserved To Mukesh Jha.. Theme images by Jason Morrow. Powered by Blogger.