以下C#代码中,关于虚方法和抽象方法使用正确的是()
A: publicabstractclassAnimal{publicAnimal(){}}publicabstractvoidRun():Animal{publicCat(){}publicvoidRun(){}}
B: publicclassAnimal{publicAnimal(){}}publicabstractvoidRun():Animal{publicCat(){}publicvoidRun(){}}
C: publicabstractclassAnimal{publicAnimal(){}publicabstractvoidRun();}publicclasscat:Animal{publicCat(){}publicoverridevoidRun(){}}
D: publicvirtualclassAnimal{publicAnimal(){}publicvirtualvoidRun();}publicclasscat:Animal{publicCat(){}publicoverridevoidRun(){}}
A: publicabstractclassAnimal{publicAnimal(){}}publicabstractvoidRun():Animal{publicCat(){}publicvoidRun(){}}
B: publicclassAnimal{publicAnimal(){}}publicabstractvoidRun():Animal{publicCat(){}publicvoidRun(){}}
C: publicabstractclassAnimal{publicAnimal(){}publicabstractvoidRun();}publicclasscat:Animal{publicCat(){}publicoverridevoidRun(){}}
D: publicvirtualclassAnimal{publicAnimal(){}publicvirtualvoidRun();}publicclasscat:Animal{publicCat(){}publicoverridevoidRun(){}}
举一反三
- 下列代码声明了3个类 class Animal{}; class Cat:publicAnimal{}; class Mouse:Animal{}; 对于这段代码,理解错误的是:
- 下列代码声明了3个类class Animal{};class Cat:publicAnimal{};class Mouse:Animal{};下列关于这些类之间关系的描述中,错误的是: A: 类Animal是类Cat的基类 B: 类Mouse从类Cat公有继承 C: 类Cat是类Animal的派生类 D: 类Mouse是类Animal的派生类
- 已知有如下定义:package cn.edu.ncu.chenyi;public interface Runnable{public void run();}package cn.edu.ncu.chenyi;public abstract class Animal implements Runnable{public void run();}关于上述两个代码说法正确的是? A: Animal编译失败,因为Animal类实现接口,不能定义为抽象类 B: Animal编译失败,因为Animal类实现接口Runnable,方法run的方法不是抽象方法,方法体不能为空; C: Animal编译失败,需要在方法run中增加修饰符abstract才能修改正确,形如:package cn.edu.ncu.chenyi;public abstract class Animal implements Runnable{ public abstract void run();} D: Animal编译成功,代码正确; E: 以上说法均不正确
- 编写抽象类Animal,其中Animal抽象类有2个抽象方法voidcry()和StringgetAnimalName(),分别表示要求动物给出自己的叫声和种类名称。然后,编写Animal类的子类:Dog,Cat类,要求实现抽象类中的抽象方法。main主方法如下:Animalanimal;animal=newDog();System.out.println(animal.getAnimalName());animal.cry();animal=newCat();System.out.println(animal.getAnimalName());animal.cry();
- (7-1)定义了Animal类、Cat类和Dog类,则代码段是正确的。 class Animal{ }; class Cat extends Animal{} class Dog extends Animal{}