Static Variables and Methods

AP Computer Science A· difficulty 2/5

public class MathUtil {
    public static int square(int n) { return n * n; }
}
// ...
System.out.println(MathUtil.square(6));

What is printed?

  • A

    36

    check_circle
  • B

    12

  • C

    6

  • D

    Compile-time error

Explanation

Static methods are called on the class. square(6) returns 36.

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

Related questions