Static Variables and Methods

AP Computer Science A· difficulty 4/5

public class T {
    static int count = 0;
    public static int next() { return ++count; }
}
public static int run() {
    int a = T.next();
    int b = T.next();
    int c = T.next();
    return a * 100 + b * 10 + c;
}
// Call: System.out.println(run());

What is printed?

  • A

    321

  • B

    111

  • C

    333

  • D

    123

    check_circle

Explanation

Sequential calls: a=1, b=2, c=3. 1<em>100 + 2</em>10 + 3 = 123.

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

Related questions