第一次打印的是你申明int i=4,j=5;时的值是4第二次打印是你secondMethod(int i){传入的参数是 7我也晕。
解决方案 »
- JAVA怎么处理这样的XML文件,IE中已经可以正常显示
- java udp穿透NAT,怎么实现?
- 关于access备份数据...
- 非swing高手莫进
- 怎样将字符串拆分?
- 如何方便地进行61.1.1.1到061.001.001.001这样的格式转换?
- 紧急求助!无法安装运行JAVA程序,100分
- 这句话Circular references do not prevent objects from being garbage collected.应该怎么翻译呢?
- JB4中的JDBTable中怎样显示标题(字段名)?
- 古典问题:有一对兔子,从出生后第3个月起
- 关于一个List 放在session里的问题!
- 一个匿名类,把它改成成员类竟然不行,真怪??
public static void main(String[] args)
{
System.out.println(i);
}
System.out.println(i);
^
1 error不行,我做过的
把I换成static 的就行了
两个this.i分别为多少啊?
由于i属于实例变量,所以只有类实例化为对象它才存在,所以main()应该写为:
public static void main(String[] args)
{
ScopeExample object=new ScopeExample();
System.out.println(object.i);
}
public static void main(String[] args)
{
ScopeExample object=new ScopeExample();
System.out.println(object.i);
object.firstMethod();
System.out.println("in firstMethod ,this.i="+object.i);
object.secondMethod(1);//这个参数1可以自己选择
System.out.println("in secondMethod ,this.i="+object.i);
}
private int i=1;
public void firstMethod(){
int i=4,j=5;
this.i=i+j;
int l=this.i;
System.out.println(l);
secondMethod(7);
}
public void secondMethod(int i){
int j=8;
this.i=i+j;
int l=this.i;
System.out.println(l);
}
public static void main(String args[]){
ScopeExample s=new ScopeExample();
s.firstMethod();
}
}
//不知道这样可不可以
public static void main(String[] args)
{
ScopeExample object=new ScopeExample();
System.out.println(object.i);
object.firstMethod();
System.out.println("in firstMethod ,this.i="+object.i);
object.secondMethod(object.i);//传入你要的参数
System.out.println("in secondMethod ,this.i="+object.i);
}
public static void main(String[] args)
{
ScopeExample object=new ScopeExample();
System.out.println(object.i);
object.firstMethod();
System.out.println("in firstMethod ,this.i="+object.i);
object.secondMethod(7);//类似你第1个方法的调用
System.out.println("in secondMethod ,this.i="+object.i);
}