A

Admin • 828.03K Points
Coach

Q. What is the output for the below code?
interface A{
public void printValue();
}

public class Test{
public static void main (String[] args){
A a1 = new A(){
public void printValue(){
System.out.println("A");
}
};
a1.printValue();
}
}

  • (A) Compilation fails due to an error on line 3
  • (B) A
  • (C) Compilation fails due to an error on line 8
  • (D) Compilation fails due to an error on line 8 D. null
  • Correct Answer - Option(B)
  • Views: 21
  • Filed under category Java
  • Hashtags:

Explanation by: Admin
The A a1 reference variable refers not to an instance of interface A, but to an instance of an anonymous (unnamed) class. So there is no compilation error.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.