1 public class Test3 {
2 //类的实例变量
3 int x=1;
4 //类的静态变量初始值为2
5 static int y=2; //类的静态变量初始值为2
6 //静态方法
7 public static void out() {
8 System.out.println("类的实例化变量x:"+new Test3().x); //必须通过类的实例化来访问x 的值
9 System.out.println("类的静态变量y:"+y);
10 }
11 public static void main(String[] args) {
12 Test3.out();
13 Test3 t=new Test3();
14 System.out.println("x="+t.x);
15 System.out.println("y="+t.y);
16 }
17
18 }
运行结果如下:
类的实例化变量x:1
类的静态变量y:2
x=1
y=2