Welcome Guest | Sign in | Register
Inner Classes - Discussion Page For Q.3033 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Inner Classes > Questions and Answers

Q: What is the output for the below code ?
public interface Ianimal {
public void eat();
}
public class Tiger {
Ianimal c = new Ianimal() {
public void eat() {
System.out.println("Tiger eat non-veg");
}
};
public void doit(){
c.eat();
}
public static void main(String... args){
Tiger t = new Tiger();
t.doit();
}
}
A. Tiger eat non-veg B. Compilation succeed but Runtime Exception
C. Compile fail : Interface can't Instantiate D. None of the above

Answer and Explanation

Answer:Tiger eat non-veg

Explanation:
This is anonymous implementer of the specified interface type. Interface is
implmented by anonymous class and output is "Tiger eat non-veg".

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.