编写 Animal 类和 Dog 类; 根据用户输入的数值,创建相应个数的 Animal 对象和 Dog 对象
编写 Animal 类和 Dog 类; 根据用户输入的数值,创建相应个数的 Animal 对象和 Dog 对象
参考答案和解析
Dog d = (Dog)new Animal();
相关考题:
在Java中,类Animal中的方法printA()定义如下:publicvoidprintA(){inta=10;intresult=10%3;System.out.println(result);}在类Dog中方法printA()定义如下:publicvoidprintA(){inta=10;System.out.println(a/3);}Dog类的定义如下:classDogextendsAnimal{…}.Animalanimal=newDog();animal.printA();以上语句输出为()。A.0B.1C.2D.3E.3.3333
有如下程序: 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;}程序的输出结果是______。
( 12 )有如下程序:#include iostreamusing namespace stdclass 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 ( ) const {return "Woof"}};void type ( Animal a ) {couta.getType ( ) ; }void speak ( Animal a ) {couta.getVoice ( ) ; }int main ( ) {Dog d; type ( d ) ; cout" speak" ; speak ( d ) ; coutendi;return 0;}运行时的输出结果是【 12 】 。
We can infer from the third paragraph that .[A] rich people are more interested in cloning humans than animals[B] cloning of animal pets is becoming a prosperous industry[C] there is no distinction between a cloned and a natural dog[D] Missy’s master pays a lot in a hope to revive the dog
若Animal是Cat,Dog的父类,则下列选项中,正确的是()。 A.Animalanimal=newCat()B.Catcat=(Cat)newDog()C.Catcat=(Cat)newAnimal()D.Animalanimal=newDog()
dog是animal的子类,下面代码错误的是_________。 A.Objecto=newDog();B.Animala=newDog();C.Objectd=(Dog)newAnimal()D.Animala=(Animal)newDog();
有如下程序: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;}运行时的输出结果是【 】
词的关系分类主要有:对比,如wet-dry(湿-干);相似,如blossom-flower(开花-花);从属,如animal-dog(动物-狗);并列,如apple-peach(苹果-桃)。
classCatextendsAnimal{}对于下述代码说法正确的是()A、Cat是Animal的子类B、Animal是Cat的子类C、Cat是Animal的超类D、Animal一定是抽象类
在Java中, 类Animal中的方法printA()定义如下: publicvoidprintA(){ inta=10; intresult=10%3; System.out.println(result);} 在类Dog中方法printA()定义如下: publicvoidprintA(){ inta=10; System.out.println(a/3);} Dog类的定义如下: classDogextendsAnimal{…}.Animalanimal=newDog();animal.printA(); 以上语句输出为()。A、0B、1C、2D、3E、3.3333
10. interface Jumper { public void jump(); } ...... 20. class Animal {} ...... 30. class Dog extends Animal { 31. Tail tail; 32. } ...... 40. class Beagle extends Dog implements Jumper { 41. public void jump() { } 42. } ....... 50. class Cat implements Jumper { 51. public void jump() { } 52. } Which three are true?()A、 Cat is-a AnimalB、 Cat is-a JumperC、 Dog is-a AnimalD、 Dog is-a JumperE、 Cat has-a AnimalF、 Beagle has-a TailG、 Beagle has-a Jumper
class Dog { } class Harrier extends Dog { } class DogTest { public static void main(String [] args) { Dog d1 = new Dog(); Harrier h1 = new Harrier(); Dog d2 = h1; Harrier h2 = (Harrier) d2; Harrier h3 = d2; } } 下面哪一项是正确的?() A、编译失败B、2个Dog对象被创建C、2个Harrier对象被创建D、3个Harrier对象被创建
现有: class Dog{ } class Harrier extends Dog { } class DogTest{ public static void main (String [] args) { Dog dl=new Dog(); Harrier hl=new Harrier(); Dog d2=hl; Harrier h2= (Harrier) d2; Harrier h3=d2; } } 下面哪一项是正确的?() A、2个Dog对象被创建B、2个Harrier对象被创建C、3个Harrier对象被创建D、编译失败
publicabstractclassAnimal{publicabstractvoidEat();publicvoidSleep(){}}以下关于C#代码地描述正确的是()。A、该段代码正确B、代码错误〃因为类中存在非抽象方法C、代码错误〃因为类中方法没有实现D、通过代码Animalan=newAnimal;可以创建一个Animal对象
11. class Animal { public String noise() { return “peep”; } } 12. class Dog extends Animal { 13. public String noise() { return “bark”; } 14. } 15. class Cat extends Animal { 16. public String noise() { return “meow”; } 17. } ..... 30. Animal animal = new Dog(); 31. Cat cat = (Cat)animal; 32. System.out.printIn(cat.noise()); What is the result?() A、 peepB、 barkC、 meowD、 Compilation fails.E、 An exception is thrown at runtime.
多选题Given: 10. interface Jumper { public void jump(); } ... 20. class Animal {} ... 30. class Dog extends Animal { 31. Tail tail; 32. } ... 40. class Beagle extends Dog implements Jumper{ 41. public void jump() {} 42. } ... 50. class Cat implements Jumper{ 51. public void jump() {} 52. }. Which three are true?()ACat is-a JumperBCat is-a AnimalCDog is-a JumperDDog is-a AnimalEBeagle has-a JumperFCat has-a AnimalGBeagle has-a Tail
单选题class Dog { } class Harrier extends Dog { } class DogTest { public static void main(String [] args) { Dog d1 = new Dog(); Harrier h1 = new Harrier(); Dog d2 = h1; Harrier h2 = (Harrier) d2; Harrier h3 = d2; } } 下面哪一项是正确的?()A编译失败B2个Dog对象被创建C2个Harrier对象被创建D3个Harrier对象被创建
单选题现有: class Dog{ } class Harrier extends Dog { } class DogTest{ public static void main (String [] args) { Dog dl=new Dog(); Harrier hl=new Harrier(); Dog d2=hl; Harrier h2= (Harrier) d2; Harrier h3=d2; } } 下面哪一项是正确的?()A2个Dog对象被创建B2个Harrier对象被创建C3个Harrier对象被创建D编译失败
单选题11. class Animal { public String noise() { return “peep”; } } 12. class Dog extends Animal { 13. public String noise() { return “bark”; } 14. } 15. class Cat extends Animal { 16. public String noise() { return “meow”; } 17. } ..... 30. Animal animal = new Dog(); 31. Cat cat = (Cat)animal; 32. System.out.printIn(cat.noise()); What is the result?()A peepB barkC meowD Compilation fails.E An exception is thrown at runtime.
单选题在Java中,类Animal中的方法printA()定义如下: public void printA() { Int a=10; Int result =10%3; System.out.println(result); } 在类Dog中方法printA()定义如下: public void printA() { Int a=10; System.out.println(a/3); } Dog类的定义如下: Class Dog extends Animal{…}. Animal animal=new Dog(); animal.printA(); 以上语句输出结果为()。A 0B 1C 2D3E3.3333
单选题publicabstractclassAnimal{publicabstractvoidEat();publicvoidSleep(){}}以下关于C#代码地描述正确的是()。A该段代码正确B代码错误〃因为类中存在非抽象方法C代码错误〃因为类中方法没有实现D通过代码Animalan=newAnimal;可以创建一个Animal对象
多选题10. interface Jumper { public void jump(); } ...... 20. class Animal {} ...... 30. class Dog extends Animal { 31. Tail tail; 32. } ...... 40. class Beagle extends Dog implements Jumper { 41. public void jump() { } 42. } ....... 50. class Cat implements Jumper { 51. public void jump() { } 52. } Which three are true?()ACat is-a AnimalBCat is-a JumperCDog is-a AnimalDDog is-a JumperECat has-a AnimalFBeagle has-a TailGBeagle has-a Jumper
单选题1. class Animal { Animal getOne() { return new Animal(); } } 2. class Dog extends Animal { 3. // insert code here 4. } 5. 6. class AnimalTest { 7. public static void main(String [] args) { 8. Animal [] animal = { new Animal(), new Dog() } ; 9. for( Animal a : animal) { 10. Animal x = a.getOne(); 11. } 12. } 13. } 和代码: 3a. Dog getOne() { return new Dog(); } 3b. Animal getOne() { return new Dog(); } 第 3 行中插入的哪项将编译且运行无异常?()A3a行B3b行C3a行或3b行D既非3a,也非3b
单选题class Animal{ Animal getOne(){return new Animal();}} class Dog extends Animal{ //insert code here } class AnimalTest{ public static void main(String[] args){ Animal[] animal={ new Animal(), new Dog()}; for(Animal a:animal){ Animal x= a.getOne(); } } } 和代码: 3a.Dog getOne() { return new Dog();} 3b.Animal getOne() { return new Dog();} 第3行中插入的哪项编译且运行无异常?A3a行或3b行B既非3a,也非3bC3a行D3b行