public class Aa { int x=1; static int y=2; public static void method()标签:静态数据,静态方法,System,访问,实例,static,Test From: https://www.cnblogs.com/liuxuefeng/p/16759205.html
//静态方法 { System.out.println("实例变量x = " + new Test().x);
//在静态方法中访问类的实例变量需首先进行类的实例化 System.out.println("静态变量y = " + y);
//在静态方法中可直接访问类的静态变量 } public static void main(String[] args) { Test.method(); Test t = new Test(); System.out.println("x = " + t.x); } }