您的位置:首页 > 编程语言 > Java开发

test5.8

2015-09-19 20:34 501 查看
第一个方法使用this就是下边的运行效果,不适用this,需要把//去掉,并且在原来//下边一行的句首加上//,从两次输出结果表明带有this的Induce()可以反复调用,否则不可以

/*create a class with two function;

 * methods:the first function induce the second one twice

 *         second with keyword this but first without;

 */

public class Test8 {
int sum=0;
//void Induce(){Addin();}
Test8 Induce(){Addin();return this;}

    void Addin(){sum++;}
public static void main(String[] args) {
Test8 f=new Test8();
//f.Induce();System.out.println(f.sum);
System.out.println(f.Induce().Induce().Induce().sum);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Java