public class Test { |
private int i; // |
Test类的实例变量 |
public int firstMethod() { |
int j = 1 ; // |
局部变量 |
// 这里能够访问i和j |
System.out.println("firstMethod |
中 |
i= "+i+" ,j="+j); |
return 1 ; |
} // firstMethod() |
方法结束 |
public int secondMethod( float f) { //method parameter |
int j = 2 ; //局部变量,跟firstMethod() |
方法中的j是不同的 |
// |
这个j的范围是限制 |
在secondMethod() |
种的 |
// |
在这个地方,可以 |
同时访问i,j,f |
System.out.println("secondMethod |
中 |
i= "+i+" ,j= "+j+" ,f="+f); |
return 2 ; |
} |
public static void main(String[] args) { |
Test t = new Test(); |
t.firstMethod(); |
t.secondMethod( 3 ); |
} |
} //源代码片段来自云代码http://yuncode.net |
|