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
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
相关文章推荐
- CvMat执行CvReshape()报错“The matrix is not continuous, thus its number of rows can not be changed”
- Variable ‘time_zone’ can’t be set to the value of ‘NULL’解决方法
- [mysql] 批量导入提示: Variable ‘character_set_client’ can’t be set to the value of ‘NULL
- mysql:Variable 'character_set_client' can't be set to the value of 'NULL'解决
- 【OpenCV学习笔记】【异常处理】一(The Matrix is not continuous, thus its number of rows can not be changed)
- (转)The final local variable xxx cannot be assigned, since it is defined in an enclosing type
- Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
- ORACLE EBS:Can't connect to X11 window server using '**' as the value of the DISPLAY variable.
- The final local variable xxx cannot be assigned, since it is defined in an enclosing type
- linux异常系列:Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
- android之“java.lang.IllegalArgumentException: Window type can not be changed after the window is add”
- The final local variable xxx cannot be assigned, since it is defined in an enclosing type
- Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
- The final local variable cannot be assigned, since it is defined in an enclosing type的解决办法(把变量从局部编程)
- 《How hard can it be? Estimating the difficulty of visual search in an image》和 PPT
- java.lang.IllegalArgumentException: Window type can not be changed after the window is added.
- java.lang.IllegalArgumentException: Window type can not be changed after the window is added.
- The final local variable xxx cannot be assigned, since it is defined in an enclosing type“,
- The final local variable xxx cannot be assigned, since it is defined in an enclosing type
- 【转】The final local variable xxx cannot be assigned, since it is defined in an enclosing type