LearnFrenzy
Sign in Take a free test

Constructors and the this Keyword · Constructors MCQ · Question 8

Why write this.name = name? Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 8 Back to Exercise

Why do constructors often contain this.name = name;?

  • A It is required syntax
  • B The parameter name hides the field, so this.name is needed to refer to the field Correct
  • C It makes the field final
  • D It copies the object
Correct Answer: Option B

Without this, name = name assigns the parameter to itself.

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