在前面几题的基础上,有子类Dog和Cat继承了父类Animal,如下空格的输出是以下哪个选项? dog = Dog(’coco’,’small’); cat = Cat(’kawaii’) >>> isinstance(dog, Animal) ___________ >>> isinstance(cat, Animal) ___________ >>> isinstance(dog, Dog) ___________ >>> isinstance(dog, Cat) ____________
A、True True False False
B、True True True False
C、True False False True
D、True True True True
第1题
A、A.Cat cat = (Cat)new Animal();
B、B.Animal a = new Cat(); Cat cat = (Cat) a;
C、C.Animal animal = new Cat();
D、D.Animal a = new Dog(); Cat cat = (Cat) a;
第3题
A、Dog[] a = new Dog[5]; a[0] = new Cat();
B、Animal a = new Animal[5]; a[0] = new Animal();
C、Dog[]a = new Dog[5]; a[0] = new Animal();
D、Cat[]a = new Cat[5]; a[0] = new Cat();
第5题
设计一个动物声音“模拟器”,希望模拟器可以模拟许多动物的叫声。要求如下: 1)编写抽象类Animal Animal抽象类有2个抽象方法cry()和getAnimaName(),即要求各种具体的动物给出自己的叫声和种类名称。 2)编写模拟器类Simulator 该类有一个playSound(Animal animal)方法,该方法的参数是Animal类型。即参数animal可以调用Animal的子类重写的cry()方法播放具体动物的声音、调用子类重写的getAnimalName()方法显示动物种类的名称。 3)编写Animal类的子类:Dog,Cat类 Dog中重写的cry()方法实现在控制台输出“bow-wow”,及其getAnimalName()方法实现输出“Dog”; Cat中重写的cry()方法实现在控制台输出“miaow”,及其getAnimalName()方法实现输出“Cat”。 4)编写主类Application(用户程序) 在主类Application的main方法中至少包含如下代码: Simulator simulator = new Simulator(); simulator.playSound(new Dog()); simulator.playSound(new Cat()); 注:此题中每个类的代码量均在3~5行左右,不复杂。
第6题
第7题
该题目和第5章习题5的编程题类似,只不过这里要求使用接口而已。 设计一个动物声音“模拟器”,希望模拟器可以模拟许多动物的叫声。要求如下: 1)编写接口Animal Animal接口有2个抽象方法cry()和getAnimaName(),即要求实现该接口的各种具体动物类给出自己的叫声和种类名称。 2)编写模拟器类Simulator 该类有一个playSound(Animal animal)方法,该方法的参数是Animal类型。即参数animal可以调用实现Animal接口类重写的cry()方法播放具体动物的声音、调用重写的getAnimalName()方法显示动物种类的名称。 3)编写实现Animal接口的Dog类和Cat类 4)编写主类Application(用户程序) 在主类Application的main方法中至少包含如下代码: Simulator simulator = new Simulator(); simulator.playSound(new Dog()); simulator.playSound(new Cat()); 附件是Simulator、Animal、Dog、Cat的UML图。 提示:参考P156例子6。
第8题
A. hypernym
B. synonym
C. homonym
D. hyponyms
第9题
A.peep
B.bark
C.meow
D.Compilationfails.
E.Anexceptionisthrownatruntime.
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!