πŸ“Š JAVA
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
πŸ’¬ Discuss
βœ… Correct Answer: (B) At line 2, constructor call

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

Explanation by: Rakesh Kumar
a constructor call (super() or this() ) must be the first statement inside a constructor.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
203
Total Visits
πŸ“½οΈ
12 mo ago
Published
πŸŽ–οΈ
Rakesh Kumar
Publisher
πŸ“ˆ
83%
Success Rate