Bird
0
0

Identify the error in this code:

medium📝 Debug Q6 of 15
Java - Inheritance
Identify the error in this code:
class Test {
  Test() {
    this();
  }
}
ARecursive constructor call causing compile error
BMissing super() call
CNo error, code is valid
DConstructor name mismatch
Step-by-Step Solution
Solution:
  1. Step 1: Analyze constructor call

    The constructor calls itself with this(), causing infinite recursion.
  2. Step 2: Understand Java restriction

    Java does not allow a constructor to call itself directly; this causes a compile-time error.
  3. Final Answer:

    Recursive constructor call causing compile error -> Option A
  4. Quick Check:

    Constructor cannot call itself directly [OK]
Quick Trick: Avoid calling same constructor inside itself [OK]
Common Mistakes:
  • Thinking this() calls super()
  • Assuming code compiles fine
  • Ignoring recursion error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes