// Inheritance: design practice // Strawberry class inheriting from Fruit public class Strawberry2 extends Fruit { private boolean isWashed; public Strawberry2() { super(1); isWashed = false; } // If strawberry is washed, eat it (return 0). // Else return 1. public int eat() { if (isWashed) return super.eat(); return 1; } // Wash the strawberry. public int wash() { if (super.eatable() && !isWashed) { isWashed = true; return 0; } return 1; } public String toString() { return "This strawberry " + (isWashed? "is" : "isn't") + " washed." + super.toString(); } public static void main(String[] args) { Strawberry2 b = new Strawberry2(); System.out.println("b is: " + b); System.out.println("Eating: " + b.eat() + " = " + b); System.out.println("Washing: " + b.wash() + " = " + b); System.out.println("Eating: " + b.eat() + " = " + b); System.out.println("Washing: " + b.wash() + " = " + b); } }