Static Variables and Methods

AP Computer Science A· difficulty 3/5

public class Thing {
    private int x;
    public static int peek() {
        return this.x;
    }
}
// ...

What is the result?

  • A

    Compile-time error

    check_circle
  • B

    0

  • C

    Run-time error

  • D

    null

Explanation

The keyword this cannot appear in a static context because no instance exists.

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

Related questions