j**a中对象的属性和行为

时间:2013.06.10 发布人:wangyuwei163

j**a中对象的属性和行为

已解决问题

谷歌wangyuwei163用户在2013.06.10提交了关于“庐山j**a中对象的属性和行为”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-08-26T08:48:45。publicclassCopyOfTransferProperty{
staticinti=47;
publicvoidcall(){
System.out.println("调用call()方法");
for(i=0;i<3;i++){
System.out.print(i+"");
if(i==2){
System.out.println("\n");
}
}
}
publicCopyOfTransferProperty(){

}
publicstaticvoidmain(String[]args){
CopyOfTransferPropertyt1=newCopyOfTransferProperty();
CopyOfTransferPropertyt2=newCopyOfTransferProperty();
CopyOfTransferPropertyt3=newCopyOfTransferProperty();

t2.i=60;
System.out.println("第一个实例对象调用变量i的结果:"+t1.i++);
***.call();
System.out.println("第二个实例对象调用变量i的结果:"+t2.i);
***.call();

}

}
在主方法中定义的t2.i=60;
输出结果t1.i++写成t1.i有什么分别.
为什么输出t2的时候结果不是60而是3.很想不明白.
新手入门请教各位高手.谢谢了.希望大家能够帮助她。

详细问题描述及疑问:publicclassCopyOfTransferProperty{
staticinti=47;
publicvoidcall(){
System.out.println("调用call()方法");
for(i=0;i<3;i++){
System.out.print(i+"");
if(i==2){
System.out.println("\n");
}
}
}
publicCopyOfTransferProperty(){

}
publicstaticvoidmain(String[]args){
CopyOfTransferPropertyt1=newCopyOfTransferProperty();
CopyOfTransferPropertyt2=newCopyOfTransferProperty();
CopyOfTransferPropertyt3=newCopyOfTransferProperty();

t2.i=60;
System.out.println("第一个实例对象调用变量i的结果:"+t1.i++);
***.call();
System.out.println("第二个实例对象调用变量i的结果:"+t2.i);
***.call();

}

}
在主方法中定义的t2.i=60;
输出结果t1.i++写成t1.i有什么分别.
为什么输出t2的时候结果不是60而是3.很想不明白.
新手入门请教各位高手.谢谢了.期待您的答案,你无异于雪中送炭,让我感激涕零 !

希望以下的回答,能够帮助你。

第1个回答

用户名:牟中虎  

输出结果t1.i++写成t1.i有什么分别.
答:输出结果是没有什么分来自别的,只是在输出结果之后,t1.i的值自增1
为什么输出t2的时候结果不是60而是3.很想不明白.
t2输出时,已红题止排手双丰经调用了***.call方法,由问答于i是一个静态变量,它的值也表现在CopyOfTransferProp顶总板棉委量合假肥erty其它所有的对象中
for(i=0;i<3;i++)满朝差兵夜统四{
System.out.print(i+"");
if(i==2){
System.out.println("\n");
}
}
循环结束后,i的值为3