gpt4 book ai didi

java - 静态变量的奇怪行为

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:15:19 25 4
gpt4 key购买 nike

<分区>

我有类AbstractsAndInterfaces:

public static AbstractsAndInterfaces instance = new AbstractsAndInterfaces();
private static final int DELTA = 5;

private static int BASE = 7;

private int x;
public AbstractsAndInterfaces()
{
//System.out.println(BASE);
//System.out.println(DELTA);
x = BASE + DELTA;
}
public static int getBASE()
{
return BASE;
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

System.out.println(AbstractsAndInterfaces.instance.x);
}

为什么打印 5?

为什么 BASE 变量未初始化?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com