静态方法中只允许访问静态数据,那么,如何在静态方法中访问类的实例成员(即没有附加static关键字的字段或方法)?
package test.two;
public class jingtaihanshu
{
int x = 3;
static int y = 4;
public static void Method()//静态方法
{
System.out.println("实例变量x = " + new jingtaihanshu().x);
System.out.println("静态变量y = " + y);
}
public static void void main(String[] args)
{jingtaihanshu.Method();
jingtaihanshuex = new jingtaihanshu();
System.out.println("x = " + ex.x);
}
}