package com.algorithm; public class Animal { class Cat { public void say(){ System.out.println("小猫喵喵叫"); } public void run(){ System.out.println("小猫跑跑跑"); } public void jump(){ System.out.println("小猫跳跳跳"); } } class Dog { public void say(){ System.out.println("小狗旺旺叫"); } public void run(){ System.out.println("小狗跑跑跑"); } public void jump(){ System.out.println("小狗跳跳跳"); } } }
package com.algorithm; public class Mammal extends Animal { public static void main(String[] args) { Mammal mammal = new Mammal(); Dog dog = mammal.new Dog(); dog.say(); dog.run(); dog.jump(); Cat cat = mammal.new Cat(); cat.say(); cat.run(); cat.jump(); } }
运行结果:
小狗旺旺叫
小狗跑跑跑
小狗跳跳跳
小猫喵喵叫
小猫跑跑跑
小猫跳跳跳