Java - 继承不同的if语句
我目前有一个带有构造函数的超类
public Bread(double price)
{
if (price > 0 && price <= 50)
{
this.price = price;
}
}
,另一个类继承了上面的带有构造函数的类:
public TigerBread(double price)
{
if (price > 0 && price <= 100)
{
this.price = price;
}
}
正如你所看到的,它们都有不同的价格范围,但是当创建价格大于 50 的 TigerBread 时,我还需要它喂入范围为 0 - 50 的超类 Bread 中,这可能吗?
谢谢你!
I currently have a super class with the constructor
public Bread(double price)
{
if (price > 0 && price <= 50)
{
this.price = price;
}
}
And another class which inhertits the above class with the constructor:
public TigerBread(double price)
{
if (price > 0 && price <= 100)
{
this.price = price;
}
}
As you can see they both have different price ranges, however when creating a TigerBread with a price greater than 50, I also need it to be fed into the super class Bread which has a range of 0 - 50, is this possible?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论