`
wsql
  • 浏览: 11793625 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

static变量

 
阅读更多
public class  StaticTest{
    private  static  int  x=100;
    public  static  void  main(String  args[] ){
        StaticTest  hs1=new  StaticTest(  );
        hs1.x++;
		System.out.println("1="+x);
        StaticTest  hs2=new  StaticTest(  );
        hs2.x++;		
		System.out.println("2="+x);
        hs1=new  StaticTest( );
        hs1.x++;
		System.out.println("3="+x);
		StaticTest.x--;
		System.out.println("4="+x);
}
}

java里面非静态的变量,不new出来他的类是一定不能用的,但是如果是static的不管new不new出来对象,都能调用



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics