您的位置:首页 > 产品设计 > UI/UE

the value of static variable can be changed after it's assigned

2005-09-04 23:12 591 查看
//the value of static variable can be changed after it's assigned
public class StaticVariable{
 static int i = 2;
 static{
  int i=5;
  System.out.println("in static initialization, i is : "+i);
  System.out.println("##################");
 }
 
 
 StaticVariable(){
  System.out.println("in constructor ,i is : "+i);
 
 }
 public static void main(String[] args){
  System.out.println("begin main....");
  StaticVariable ff = new StaticVariable();
  StaticVariable hh = new StaticVariable();
  i=3;//the value of static variable can be changed after it's assigned.
  System.out.println(i);
  
  System.out.println("---------------");
  StaticVariable tt = new StaticVariable();
  StaticVariable bb = new StaticVariable();
 }
}
//如果有多个static 变量,按顺序依次执行。同一个变量也算一次初始化
1. class StaticClass
2. {
3.  static int a = 7;
4.  static {a += 5;}
5.
6.  public static void main(String args[])
7.  {
8.   System.out.prinltn("a = " + a);
9.  }
10.  static {a /= 3;}
11. }
//结果是:a= 4
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐