public class EggCake {
int eggCount;
public EggCake(int eggCount)
{
this.eggCount = eggCount;
}
public EggCake()
{
this(1);
}
public static void main(String[] args) {
EggCake cake1 = new EggCake();
System.out.println("顾客不要求加蛋的数量,饼里会有" + cake1.eggCount + "个蛋。");
EggCake cake2 = new EggCake(2);
System.out.println("顾客要求加2个蛋,饼里会有" + cake2.eggCount + "个蛋。");
}
}
Java学习日志15:this关键字的应用
最新推荐文章于 2024-11-12 21:14:07 发布