Java课本第五章编程题

    科技2022-07-15  116

    package com.company; public class Main { public static void main(String[] args) { Simulator simulator = new Simulator(); simulator.playSound(new Dog()); simulator.playSound(new Cat()); } } class Simulator { void playSound(Animal a) { a.cry(); } } abstract class Animal extends Simulator { abstract void cry(); abstract String getAnimalName(); } class Dog extends Animal { void cry() { System.out.println("Dog cry!"); } String getAnimalName() { return "Dog"; } } class Cat extends Animal { void cry() { System.out.println("Cat cry!"); } String getAnimalName() { return "Cat"; } }

     

    Processed: 0.019, SQL: 8