LearnFrenzy
Sign in Take a free test

Constructors and the this Keyword · Constructors MCQ · Question 20

Constructors calling each other in a loop Answer, explanation & discussion

  • MCQ
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 20 Back to Exercise

What happens if A() calls this(1) and A(int x) calls this()?

  • A StackOverflowError at run time
  • B Compile error: recursive constructor invocation Correct
  • C Each runs once
  • D The compiler picks one
Correct Answer: Option B

javac detects constructor cycles.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links