publicclassPet{}publicclassCatextendsPet{}执行代码Catc=newCat();Petp=(Pet)c;下列哪项是正确的? A.Petp=(Pet)c正常执行B.Petp=(Pet)c编译错误C.Petp=(Pet)c运行错误D.以上都不对

publicclassPet{}publicclassCatextendsPet{}执行代码Catc=newCat();Petp=(Pet)c;下列哪项是正确的?

A.Petp=(Pet)c正常执行

B.Petp=(Pet)c编译错误

C.Petp=(Pet)c运行错误

D.以上都不对


相关考题:

如下程序的输出结果是______。 include using namespace std; class Pet{ char nam 如下程序的输出结果是______。include<iostream>using namespace std;class Pet{char name[10];public:Pet(char*nanle){strcpy(this->name,name);}const char*getName( )const{return name;}virtual void call( )eonst=0;};class Dog:public Pet{public:Dog(char*name):Pet(name){ }void call( )eonst{cout<<"汪汪叫";}};class Cat:public Pet{public:Cat(char*name):Pet(name){ }void call( )const{eout<<"喵喵叫";}};int main( ){Pet*petl=new Dog("哈克"),*pet2=new Cat("吉米");eout<<petl->getName( );petl->call( );eout<<endl;cout<<pet2->getName( );pet2->call( );eout<<endl;return 0;}

若Animal是Cat,Dog的父类,则下列选项中,正确的是()。 A.Animalanimal=newCat()B.Catcat=(Cat)newDog()C.Catcat=(Cat)newAnimal()D.Animalanimal=newDog()

publicclassPet{publicvoidspeak(){System.out.print(Pet”);}}publicclassCatextendsPet{publicvoidspeak(){System.out.print(Cat”);}}publicclassDogextendsPet{publicvoidspeak(){System.out.print(Dog”);}}执行代码Pet[]p={newCat(),newDog(),newPet()};for(inti=0;i〈p.length;i++)p[i].speak();后输出的内容是哪项?()A.PetPetPetB.CatCatCatC.CatDogPetD.CatDogDog

publicclassPet{privateStringname;publicPet(){System.out.print(1);}publicPet(Stringname){System.out.print(2);}}publicclassDogextendsPet{publicDog(){System.out.print(4);}publicDog(Stringname){super(name);System.out.print(3);}}执行newDog(棕熊”);后程序输出是哪项?()A.33B.13C.23D.123

publicclassPet{privateStringname;publicPet(Stringname){this.name=name;}publicvoidspeak(){System.out.print(name);}}publicclassDogextendsPet{publicDog(Stringname){super(name);}publicvoidspeak(){super.speak();System.out.print(Dog”);}}执行代码Petpet=newDog(京巴”);pet.speak();后输出的内容是哪项?()A.京巴B.京巴DogC.nullD.Dog京巴

现有:publicclassPet()publicclassCatextendsPet{)执行代码Catc-newCat();Petp=(Pet)c;后下列哪项是正确的?() A.Petp=(Pet)c运行错误B.Petp=(Pet)c编译错误C.Petp=(Pet)c止常执行D.以上都不对

有如下程序: include using namespace std; class Pet{ char name[10]; public: Pet(c 有如下程序:include<iostream>using namespace std;class Pet{char name[10];public:Pet(char*name){strcpy(this->name,name);}const char*getName()const {return name;}virtual void call()const=0;};class Dog:public Pet{public:Dog(char*name):Pet(name){}void call()const{cout<<"汪汪叫":}};class Cat:public Pet{public:Cat(char*name):Pet(name){}void call()const{cout<<"喵喵叫";}};int main(){Pet*pet1=new Dog("哈克"),*pet2=new Cat("吉米");cout<<pet1->getName();pet1->call();cout<<end1;cout<<pet2->getName();pet2->call();cout<<end1;return 0;}程序的输出结果是______。

若有父类Animal及其两个子类Cat、Dog,则以下类型转换正确的有()A.Cat cat = (Cat)new Animal();B.Animal a = new Cat(); Cat cat = (Cat) a;C.Animal animal = new Cat();D.Animal a = new Dog(); Cat cat = (Cat) a;

【单选题】(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();