联级调用

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 @ 2021-06-08 09:11  Zwyooo  阅读(23)  评论(0编辑  收藏  举报