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);
}
}
/*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对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- 介绍一款信息管理系统的开源框架---jeecg
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- 插入排序
- 冒泡排序
- 堆排序
- 快速排序
- 二叉查找树
- [原创]java局域网聊天系统