静态变量可以通过类和实例操作

xiaoxiao2021-02-28  82

/** * @author 欢迎加入Java技术交流群:646766275 * */ public class Test { private static int x = 100; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Test test1 = new Test(); test1.x++; Test test2 = new Test(); test2.x++; test1 = new Test(); test1.x++; Test.x--; System.out.println(x); } }

A. 程序通过编译,输出:103 B. 23行不能通过编译,因为x是私有静态变量 C. 15行不能通过编译,因为引用了私有静态变量 D. 程序通过编译,输出:102

正确答案:D

转载请注明原文地址: https://www.6miu.com/read-2623399.html

最新回复(0)