// Inheritance: design practice // Banana class inheriting from Fruit public class Banana2 extends Fruit { private boolean isPeeled; public Banana2() { super(5); isPeeled = false; } // If banana is peeled, then eat a bite (return 0). // Else return 1. public int eat() { if (isPeeled) return super.eat(); return 1; } // Peel the banana, assuming it isn't already peeled. public int peel() { if (!isPeeled) { isPeeled = true; return 0; } return 1; } public String toString() { return "This banana " + (isPeeled? "is" : "isn't") + " peeled." + super.toString(); } public static void main(String[] args) { Banana2 b = new Banana2(); System.out.println("b is: " + b); System.out.println("Eating: " + b.eat() + " = " + b); System.out.println("Peeling: " + b.peel() + " = " + b); System.out.println("Eating: " + b.eat() + " = " + b); System.out.println("Peeling: " + b.peel() + " = " + b); } }