Welcome Guest | Sign in | Register
Inner Classes - Discussion Page For Q.3017 | 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. Compile Error 
C. Tech D. anonymous tech Tech

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.
Therefore 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.