this Keyword

AP Computer Science A· difficulty 3/5

public class Point {
    private int x, y;
    public Point(int x, int y) {
        /* missing */
        this.y = y;
    }
}

Which line replaces /* missing */?

  • A

    this.x = this.x;

  • B

    x = x;

  • C

    this.x = x;

    check_circle
  • D

    x = this.x;

Explanation

Use this.x to refer to the field shadowed by the parameter; otherwise the assignment is parameter-to-itself.

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

Related questions