package zzz; // 《创建多态》 public class Demo1 { public static void main(String[] args) { Fish fish = new Fish(); fish.eat(); Rice rice = new Rice(); rice.eatSomething(); Apple apple = new Apple(); apple.eatFruit(); } } class Food { protected String food = "food"; public void eat() { System.out.println("eat "+food); } } class Fish extends Food { private String food = "fish"; @Override public void eat() { System.out.println("eat "+ super.food + ", such as "+this.food); } } abstract class Something { protected String something = "something"; public abstract void eatSomething(); } class Rice extends Something { private String something = "rice"; public void eatSomething() { System.out.println("eat "+super.something+", such as "+this.something); } } interface Fruit { // fruit默认修饰符 public static final String fruit = "fruit"; public void eatFruit(); } class Apple implements Fruit { // 疑问:如何访问Fruit接口里的fruit成员变量? private String fruit = "apple"; @Override public void eatFruit() { System.out.println("eat "+ this.fruit +" ..."); } }