this Keyword

AP Computer Science A· difficulty 4/5

In <code>public Dog(String name) { this.name = name; }</code>, what is <code>this.name</code>?

  • A

    A static field

  • B

    The parameter

  • C

    Compile error

  • D

    The instance variable (distinguished from parameter)

    check_circle

Explanation

<code>this.name</code> refers to the instance field; <code>name</code> alone refers to the parameter (which shadows the field).

Want 10 more like this — adaptive to your weak spots?

Related questions

AP Computer Science A · this Keyword Practice Question | Acemy