gpt4 book ai didi

java - 能够改变静态变量值

转载 作者:行者123 更新时间:2023-11-30 10:16:38 25 4
gpt4 key购买 nike

<分区>

如以下链接所述Link

Static variables are initialized only once, at the start of the execution. These variables will be initialized first, before the initialization of any instance variables.
A single copy to be shared by all instances of the class.

但是我可以改变静态变量的值

class Test {
static int a =10;
public static void main(String args[])
{
a=20;
System.out.println("rest of the code...");
Test1 t= new Test1();
t.m();
}
}

public class Test1 {
void m ()
{
System.out.println(Test.a);
}
}

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