public class Number {
private int i;
public Number(int i){
this.i=i;
}
/*
* 判断数值大小的方法,每次调用这个方法都要新建m,n两个数值。
*/
public void isBornBoomer(){
int m = 5;
int n =10;
if(i>5 & i<10){
System.out.println("该数大于5小于10");
}
}
public static void main(String[] args) {
Number p =new Number(8);
p.isBornBoomer();
}
} public class StaticNum {
private int i;
private static int m;
private static int n;
/*
* 使用一次,只在类加载的过程加载一次即可,为了JVM。
*/
static{
m=5;
n=10;
}
public StaticNum(int i){
this.i=i;
}
public void BooleanNumber(int i){
if(i>StaticNum.m & StaticNum.n<10){
System.out.println("静态块的使用");
}
}
public static void main(String[] args) {
}
} public class Test {
public int aMethod() {
static int i = 0;
i++;
return i;
}
public static void main (String args[]) {
Test test = new Test();
test.aMethod();
int j = test.aMethod();
System.out.println(j);
}
} | 欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |