如果您有任何疑问,可以在下面询问或输入您要寻找的!
public class Leaf { private int i = 0; //此属性值用于检验 Leaf increment(){ //定义方法increment(),返回值是Leaf类的对象 i++; return__________________;//将当前对象的地址作为返回值返回 } void print() { System.out.println(" i = " + i); } public static void main(String args[]){ Leaf x =__new Leaf()____; //创建Leaf类的对象x x.increment().increment().increment().print(); }//多次调用方法increment(),返回的都是x的地址,i 值表示调用次数 } 输出结果为 i = ____________________输出为什么是3
?
public class Leaf {
private int i = 0; // 此属性值用于检验
Leaf increment(){ //定义方法increment(),返回值是Leaf类的对象
i++;
return this;//将当前对象的地址作为返回值返回
}
void print() {
System.out.println(" i = " + i);
}
public static void main(String args[]){
Leaf x =new Leaf(); //创建Leaf类的对象x
x.increment().increment().increment().print();
}// 多次调用方法increment(),返回的都是x的地址,i 值表示调用次数
}
i = 3