Welcome Guest | Sign in | Register
Inner Classes - Discussion Page For Q.3022 | 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 abstract class A {
public void printValue(){
System.out.println("A");
}
}
1. public class Test{
2. public static void main (String[] args){
3. A a1 = new A() {
4. };
5. a1.printValue();
6. }
7. }
A. Compilation fails due to an error on line 3 B. A
C. Compilation fails due to an error on line 5 D. null

Answer and Explanation

Answer:A

Explanation:
The A a1 reference variable refers not to an instance of abstract class A, but to an
instance of an anonymous (unnamed) subclass of A. So no compilation error.

Comment on this Question

Name:

Loading...




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