Scope and Access

AP Computer Science A· difficulty 3/5

Inside a class's instance method, accessing instance field <code>count</code>

  • A

    Cannot access; must use getter

  • B

    this->count

  • C

    Dog.count only

  • D

    count or this.count (both work)

    check_circle

Explanation

Either is valid; <code>this.</code> is mandatory only when shadowed by a parameter.

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

Related questions