【发布时间】:2016-06-27 07:04:28
【问题描述】:
我们知道在java中静态变量是不会被继承的。但是在下面的代码中,我没有收到任何错误,因为我想在子类中初始化静态变量。
class s
{
static int x;
}
class aaa extends s
{
void fun()
{
x=2;
System.out.println(x);
}
public static void main(String args[])
{
aaa w=new aaa();
w.fun();
}
}
【问题讨论】: