静态变量2

阅读更多
写出下来代码的输出结果:
package com.fatedgar.other;

public class Foo {
	static public int v,r;
	public int x,y;
	public Foo(){
		x=1;
		y=2;
		v=3;
		r=4;
	}
	
	public void getInfo(){
		System.out.println(x+","+y+","+v+","+r);
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Foo f1=new Foo();
		Foo f2=new Foo();
		
		f1.v=10;
		f2.v=20;
		
		f1.r=50;
		f2.r=60;
		
		f1.x=100;
		f2.x=200;
		
		f1.y=500;
		f2.y=600;
		
		f1.getInfo();
		f2.getInfo();
	}

}


结果是:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100,500,20,60
200,600,20,60

你可能感兴趣的:(静态变量的输出,静态变量,静态变量的赋值)