A

Admin • 833K Points
Coach

Q. The following code contains one compilation error, find it?
public class Test {
Test() { } // line 1
static void Test() { this(); } // line 2
public static void main(String[] args) { // line 3
Test(); // line 4
}
}

  • (A) At line 1, constructor Tester must be marked public like its class
  • (B) At line 2, constructor call
  • (C) At line 3, compilation error, ambiguity problem, compiler can't determine whether a constructor
  • (D) At line 4
  • Correct Answer - Option(B)
  • Views: 22
  • Filed under category Java
  • Hashtags:

Explanation by: Admin

a constructor call (super() or this() ) must be the first statement inside a constructor.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.