Constructors

AP Computer Science A· difficulty 4/5

<code>class Point { private int x, y; public Point(int x, int y) { this.x = x; this.y = y; } } </code></pre> Why use <code>this.</code>?

  • A

    Required by Java

  • B

    Disambiguates between parameter <code>x</code> and field <code>x</code>

    check_circle
  • C

    For static methods

  • D

    Optimizes performance

Explanation

Without <code>this.</code>, both names refer to the parameter (shadowing).

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

Related questions