static 修饰的成员 — 程序设计选择题
题目
某类 Library 中定义如下成员:static int total = 5; int num = 1; 以及静态方法 static void show(){ }。现尝试在 show() 方法体内直接写 total += 1; 和 num += 1; 两条语句。下列说法正确的是:A. 两条语句均能通过编译,因为静态方法随类加载即存在 B. total += 1; 能通过编译,num += 1; 不能,因为静态方法中缺少对象上下文,不能直接访问非静态成员 C. num += 1; 能通过编译,total += 1; 不能,因为静态成员不能在静态方法中修改 D. 两条语句均不能通过编译,静态方法中禁止访问任何成员变量