A: abstract class Cat: Animal { abstract public void Move(); }
B: abstract class Cat: Animal { virtual public void Move(){Console.Write(Console.Write("Move!");)} }
C: abstract class Cat: Animal { public void Move(){Console.Write(Console.Write("Move!");)}; }
D: abstract class Cat: Animal { public void Eat(){Console.Write(Console.Write("Eat!");)}; }
举一反三
- 请阅读下面的程序,写出运行结果,如果编译失败,写明失败原因。 abstract class Animal{ public final abstract void eat(); } class Cat extends Animal{ public void eat(){ System.out.println("cat...fish"); } } class CatDemo{ public static void main(String[] args){ Animal a = new Cat(); a.eat(); } }
- 下面关于抽象类定义合法的是( ) A: class Animal { abstract void grow(); } B: abstract Animal { abstract void grow(); } C: class abstract Animal { abstract void grow(); } D: abstract class Animal { abstract void grow(); }
- 下列抽象类的定义合法的是( )。 A: abstract Animal {abstract void growl();} B: abstract class Animal {abstract void growl();} C: class abstract Animal {abstract void growl();} D: abstract class Animal {abstract void growl() {System.out.println(“growl”);}}
- 下列类定义中哪些是合法的抽象类的定义? A: abstract Animal{abstract void grow();} B: class abstract Animal{abstract void growl();} C: abstract class Animal{abstract void growl();} D: abstract class Animal{abstract void grow(){System.out.println("growl")};
- 下列类定义中()是合法的抽象类的定义。 A: abstract<br/>Animal {abstract void growl();} B: abstract<br/>class Animal {<br/>abstract<br/>void growl() { System.out.println(“growl”);}<br/>} C: class<br/>abstract Animal {abstract void growl();} D: abstract<br/>class Animal {abstract void growl();}
内容
- 0
下列类定义中属于合法的抽象类的定义的是() A: A.abstract Animal{abstract void growl()} B: B.class abstract Animal{abstract void growl()} C: C.abstract class Animal{abstract void growl()} D: D.abstract class Animal{ abstract void growl(){System.out.println("growl")};}
- 1
下列代码输出为( ): class Father{ public void F() { Console.Write("A.F"); } public virtual void G() { Console.Write("A.G"); } } class Son: Father{ new public void F() { Console.Write("B.F"); } public override void G() { Console.Write("B.G"); } } class override_new{ static void Main() { Son b = new Son(); Father a = b; a.F(); b.F(); a.G(); b.G(); } }
- 2
已知有如下定义: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: 以上说法均不正确
- 3
已知有如下代码:public abstract class Animal{public abstract void run();public abstract void eat();}public class Tiger extends Animal{}则关于上述两个类说法正确的是? A: Animal是Tiger的父类 B: Tiger是Animal的子类 C: Tiger是抽象类,因为它继承了抽象类 D: Tiger类编译失败,因为它继承了Animal抽象类的方法,并没有对这些方法定义,所以编译失败 E: Tiger类编译成功
- 4
下面类的定义,哪个是合法的抽象类定义? A: class A { abstract void unfinished() { } } B: class A { abstract void unfinished(); } C: abstract class A { abstract void unfinished(); } D: public class abstract A { abstract void unfinished(); }