Superclass
Superclass
class Food {
// Overloaded Constructors
// Constructor that initializes food with given calories and expiration date
this.caloriesPerServing = caloriesPerServing;
this.expiration = expiration;
public Food() {
this(0, "Unknown");
// Overridden Methods
System.out.println("Preparing food...");
System.out.println("Selling food...");
// Subclass: Fruit
super(caloriesPerServing, expiration);
this.isSweet = isSweet;
public Fruit() {
}
// Overriding prepare method for fruits
@Override
@Override
System.out.println("Selling fruit...");
@Override
super.displayInfo();
// Subclass: Vegetables
super(caloriesPerServing, expiration);
this.isLeafy = isLeafy;
public Vegetables() {
@Override
System.out.println("Chopping vegetables...");
@Override
System.out.println("Selling vegetables...");
@Override
public void displayInfo() {
super.displayInfo();
// Subclass: Meat
super(caloriesPerServing, expiration);
this.meatType = meatType;
public Meat() {
@Override
System.out.println("Cooking meat...");
}
@Override
System.out.println("Selling meat...");
@Override
super.displayInfo();
apple.displayInfo();
apple.prepare();
apple.sell();
System.out.println();
spinach.displayInfo();
spinach.prepare();
spinach.sell();
System.out.println();
beef.displayInfo();
beef.prepare();
beef.sell();