public class ScopeTest {

    int j;
    int k;

    public static void main(String[] args) {
        new ScopeTest().doStuff();
    }

    void doStuff() {
        int x = 5;
        doStuff2();
        System.out.println("x");
    }

    void doStuff2() {
        int y = 7;
        System.out.println("y");
        for (int z = 0; z < 5; z++) {
            System.out.println("z");
            System.out.println("y");
        }
    }
}

Which two items are fields?

A. j
B. k
C. x
D. y
E. z

题解

这个题目是在问,哪两个变量是字段。字段就是类别或是对象变量。因此只有选项 A 的「j」和选项 B 的「k」符合。