11.classAnimal{publicStringnoise(){returnpeep”;}}12.classDogextendsAnimal{13.publicStringnoise(){returnbark”;}14.}15.classCatextendsAnimal{16.publicStringnoise(){returnmeow”;}17.}.....30.Animalanimal=newDog();31.Catcat=(Cat)animal;32.System.out.printIn(cat.noise());Whatistheresult?()A.peepB.barkC.meowD.Compilationfails.E.Anexceptionisthrownatruntime.
11.classAnimal{publicStringnoise(){returnpeep”;}}12.classDogextendsAnimal{13.publicStringnoise(){returnbark”;}14.}15.classCatextendsAnimal{16.publicStringnoise(){returnmeow”;}17.}.....30.Animalanimal=newDog();31.Catcat=(Cat)animal;32.System.out.printIn(cat.noise());Whatistheresult?()
A.peep
B.bark
C.meow
D.Compilationfails.
E.Anexceptionisthrownatruntime.
相关考题:
有如下程序: include using namespaee std;class Animal{ public: virtual char*g 有如下程序:include<iostream>using namespaee std;c lass Animal{public:virtual char*getType( )const{return"Animal";}virtual char*getVoice( )const{return"Voice";}};class Dog:public Animal{public:char*getType( )const{return"Dog";}char*getVoice( )eonst{return"Woof";}};void type(AnimalA) {cout<<a.getType( );}void speak(Animal A) {eout<<a.getVoice( );}int main( ){Dog d;type(D) ;cout<<"speak";speak(D) ;cout return 0;}程序的输出结果是______。
classAnimal{AnimalgetOne(){returnnewAnimal();}}classDogextendsAnimal{//insertcodehere}classAnimalTest{publicstaticvoidmain(String[]args){Animal[]animal={newAnimal(),newDog()};for(Animala:animal){Animalx=a.getOne();}}}和代码:3a.DoggetOne(){returnnewDog();}3b.AnimalgetOne(){returnnewDog();}第3行中插入的哪项编译且运行无异常?A.3a行或3b行B.既非3a,也非3bC.3a行D.3b行
1.classAnimal{AnimalgetOne(){returnnewAnimal();}}2.classDogextendsAnimal{3.//insertcodehere4.}5.6.classAnimalTest{7.publicstaticvoidmain(String[]args){8.Animal[]animal={newAnimal(),newDog()};9.for(Animala:animal){10.Animalx=a.getOne();11.}12.}13.}和代码:3a.DoggetOne(){returnnewDog();}3b.AnimalgetOne(){returnnewDog();}第3行中插入的哪项将编译且运行无异常?()A.3a行B.3b行C.3a行或3b行D.既非3a,也非3b
10.interfaceJumper{publicvoidjump();}......20.classAnimal{}......30.classDogextendsAnimal{31.Tailtail;32.}......40.classBeagleextendsDogimplementsJumper{41.publicvoidjump(){}42.}.......50.classCatimplementsJumper{51.publicvoidjump(){}52.}Whichthreearetrue?()A.Catis-aAnimalB.Catis-aJumperC.Dogis-aAnimalD.Dogis-aJumperE.Cathas-aAnimalF.Beaglehas-aTailG.Beaglehas-aJumper
Given:10.interfaceJumper{publicvoidjump();}...20.classAnimal{}...30.classDogextendsAnimal{31.Tailtail;32.}...40.classBeagleextendsDogimplementsJumper{41.publicvoidjump(){}42.}...50.classCatimplementsJumper{51.publicvoidjump(){}52.}.Whichthreearetrue?()A.Catis-aJumperB.Catis-aAnimalC.Dogis-aJumperD.Dogis-aAnimalE.Beaglehas-aJumperF.Cathas-aAnimalG.Beaglehas-aTail
有如下程序:ncludeiostreamusing namespace std;class Animal{public:virtual char*getType()const{return“Animal”;}virtual char*getVoice()const{return“Voice”;}};class Dog:public Animal{public:char*getType()const{rgturn“Dog”;}char*getVoice()const{retum“Woof”;}};void type(AnimalA){couta.getType();}void speak(AnimalA){couta.getVoice();}int main(){Dog d.type(D);tout“speak”;speak(D);coutendl;return 0;}运行时的输出结果是【 】
以下哪个正确定义抽象类?A.class Animal { abstract void growl(); }B.abstract Animal {abstract void growl();}C.class abstract Animal {abstract void growl();}D.abstract class Animal {abstract void growl();}
编译并运行以下程序,以下描述哪个选项是正确 class Animal{ protected boolean equals(String str) { return super.equals(str); } }A.编译通过但运行时出错B.编译运行都不对C.编译通过运行无异常D.不能成功编译
【单选题】(7-1)定义了Animal类、Cat类和Dog类,则()代码段是正确的。 class Animal{ }; class Cat extends Animal{} class Dog extends Animal{}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();