Unit 7, Lesson 5, bubble 4
public class Product {
private String name;
private int quantity;
public Product(String name, int quantity) {
this.name = name;
this.quantity = quantity;
}
public int getQuantity() {
return quantity;
}
public void decreaseQuantity(int amount) {
quantity -= amount;
}
}
public class LimitedProduct extends Product {
private int limit;
public LimitedProduct(String name, int quantity, int limit) {
super(name, quantity);
this.limit = limit;
}
public void decreaseQuantity(int amount) {
if (quantity - amount >= limit) {
quantity -= amount;
}
}
}
Which of the following best describes the output of the code segment when a Product
object and a LimitedProduct
object are created with the same quantity and limit values?
The key states the answer is :
C. The LimitedProduct object will have a lower quantity than the Product object.
Wouldn’t this be the opposite? Wouldn’t the Product object continue to decrease, and the LimitedProduct object be higher due to the If statement in decreaseQuantity method that wouldn’t do anything if the condition wasn’t met.
All help is appreciated. Thank you.