java联级调用
源代码:
package 课堂4;
public class Mycounter {
private int a;
public Mycounter(int a)
{
this.a=a;
}
public Mycounter()
{
}
public Mycounter increase(int x)
{
this.a+=x;
return this;
}
public Mycounter decrease(int x)
{
this.a-=x;
return this;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Mycounter m1=new Mycounter(100);
System.out.println(m1.increase(20).decrease(40).a);
}
}
结果截图:
posted on 2017-10-27 09:06 xiaohaigege666 阅读(83) 评论(0) 编辑 收藏 举报