Welcome Guest | Sign in | Register
Inner Classes - Discussion Page For Q.3032 | 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 class Tech {
public void tech() {
System.out.println("Tech");
}
}
public class Atech {
Tech a = new Tech() {
public void tech() {
System.out.println("anonymous tech");
}
};
public void dothis() {
a.tech();
}
public static void main(String... args){
Atech atech = new Atech();
atech.dothis();
}
}
A. anonymous tech B. Tech
C. Compilation fails D. None of the above

Answer and Explanation

Answer:anonymous tech

Explanation:
This is anonymous subclass of the specified class type. anonymous inner class
( anonymous subclass ) overriden the Tech super class of tech() method. So Subclass method will get called.

Comment on this Question

Name:

Loading...




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