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