Static Variables and Methods

AP Computer Science A· difficulty 2/5

public class Util {
    public static int doubleIt(int n) { return n * 2; }
}
// ...
Util u = new Util();
System.out.println(u.doubleIt(7));

What is printed?

  • A

    14

    check_circle
  • B

    7

  • C

    Compile-time error

  • D

    0

Explanation

Although calling a static method through an instance is discouraged, it compiles; the method returns 14.

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

Related questions