现有: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.以上都不对
相关考题:
publicclassPet{}publicclassCatextendsPet{}执行代码Catc=newCat();Petp=(Pet)c;下列哪项是正确的? A.Petp=(Pet)c正常执行B.Petp=(Pet)c编译错误C.Petp=(Pet)c运行错误D.以上都不对
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京巴
现有:classA{publicStringname=a}classBextendsA{publicStringname=b}执行如下代码后的结果是哪项?()Aa=newB();System.out.println(a.name); A.aB.bC.编译失败D.运行时抛出异常
现有:classPencil{publicvoidwrite(Stringcontent){System.out.println(Write,+content){}}classRubberPencilextendsPencil{publicvoidwrite(Stringcontent){System.out.println(RubberWrite+content);}publicvoiderase(Stringcontent)}}执行下列代码的结果是哪项?()Pencilpen=newPencil();((RubberPencil)pen).write(Hello);A.WriteHelloB.RubberWriteHelloC.编译失败D.运行时抛出异常
try{ 代码块1 } catch{ 代码块2 } finally{ 代码块3 } } 针对对异常处理,以下哪些描述是正确的。A.代码块1 是可能出现问题的代码;B.代码块2 出现异常后才会执行的代码;C.代码块2 不出现异常后也会执行的代码;D.代码块3 无论出现异常与否,都会执行的代码;