第七章继承多态一、选择题:1、分析:class A {A() { }}class B extends A { //系统自动生成的构造方法和类的访问权限一样}哪两种说法是正确的? ( )A:类B的构造方法是public的. B:类B的构造方法包含对this()的调用. C:类B的构造方法没有参数. D:类B的构造方法包含对super()的调用.2、运行结果是:()class Base {Base() { System.out.print("Base"); }}public class Alpha extends Base {public static void main( String[] args ) {new Alpha();new Base();}}A: Base B: BaseBase C: 编译失败. D: 没有输出. E: 运行时异常. 3. 程序的运行结果是?()A: 编译失败. B: hello from a C: hello from bD: hello from b E: hello from ahello from a hello from b4. 运行结果是:()class TestSuper {TestSuper(int i) { }}class TestSub extends TestSuper{ }class TestAll {public static void main (String [] args) {new TestSub();}}A: 编译失败. B: 程序运行没有异常.C: 第7行抛出异常. D: 第2行抛出异常.5. 程序的运行结果是?()A: 0 B: 1 C: 2 D: 编译失败.6. 对于语句"B is a D" 和"B has a C",一下哪两种说法是正确的? ( ) A:D是B. B:B是D. C:D是C. D:B是C. E:D继承B.F:B 继承D.7. 运行结果是?()A: 1 B: 2 C: 第8行编译失败. D: 第14行编译失败.8. 分析:public class ConstOver {public ConstOver(int x, int y, int z) {}}哪两个是对ConstOver 的构造方法的重载? ( )A:ConstOver() { } B:protected int ConstOver() { }C:private ConstOver(int z, int y, byte x) { }D:public Object ConstOver(int x, int y, int z) { }E:public void ConstOver(byte x, byte y, byte z) { }9. 运行结果是?()A: 4,4 B: 4,5 C: 5,4 D: 5,5 E: 编译失败.10. 分析:public class X {public X aMethod() { return this;}}1) public class Y extends X {2)3) }在第2行可以插入哪两项? ( )A:public void aMethod() { } B:private void aMethod() { }C:public void aMethod(String s) { } D:private Y aMethod() { return null; } E:public X aMethod() { return new Y(); }11. 运行结果是?()A: 4,4 B: 4,5 C: 5,4 D: 5,5 E: 编译失败.12. 以下哪两个重载了方法setVar()? ( )public class MethodOver {public void setVar(int a, int b, float c) {}}A:private void setVar(int a, float c, int b) { } B:public int setVar(int a, float c, int b) {return a;}C:protected void setVar(int a, int b, float c) { } D:public int setVar(int a, int b, float c) {return a;}E:protected float setVar(int a, int b, float c) {return c;}13. 分析:1) class BaseClass {2) private float x = 1.0f;3) protected void setVar(float f) { x = f; }4) }5) class SubClass extends BaseClass {6) private float x = 2.0f;7) // insert code here8) }在第7行插入哪两个覆盖了方法setVar()? ( )A:void setVar(float f) { x = f; } B:public void setVar(int f) { x = f; } C:public void setVar(float f) { x = f; } D:public double setVar(float f){ return f; }E:public final void setVar(float f) { x = f; } F:protected float setVar() { x = 3.0f; return 3.0f; }14. 运行结果是?( )A: 1 B: 2 C: 运行时异常. D: 第8行编译错误. E: 第14行编译错误.15. 分析:class A {protected int method1(int a, int b) { return 0; }}在A的子类中,以下哪两个方法是合法的? ( )A:public int method1(int a, int b) { return 0; } B:private int method1(int a, long b) { return 0; }C:private int method1(int a, int b) { return 0; } D:public short method1(int a, int b) { return 0; }E:static protected int method1(int a, int b) { return 0; }16. 分析:1) public abstract class Test {2) public abstract void methodA();3)4) public abstract void methodB()5) {6) System.out.println("Hello");7) }8) }哪两种改法,可以使程序通过编译? ( )A:给方法methodA()加方法体C:在Test的声明中去掉abstractB:用";"替换第5-7行D:在方法methodA()的声明中去掉abstract E: 在方法methodB()的声明中去掉abstract17. 运行结果是:()1) abstract class AbstractIt {2) abstract float getFloat();3) }4) public class AbstractTest extends AbstractIt {5) private float f1 = 1.0f;6) private float getFloat() { return f1; }7) }A: 编译成功. B: 运行时异常. C: 第2行编译失败. D: 第6行编译失败.18. 在接口中哪两个方法的声明是合法的? ( )A:void method1(); B:public void method2(); C:static public void method5();D:protected void method3(); E:final public void method4();19. 分析:1) public interface Foo {2) int k = 4;3) }哪三项与第2行等价? ( )A:final int k = 4; B:public int k = 4; C:static int k = 4;D:abstract int k = 4; E:volatile int k = 4; F:protected int k = 4;20. 分析:interface Inter { }class A implements Inter { }class B extends A {B() {A[] arr = new A[10];boolean b1 = this instanceof Inter;boolean b2 = arr instanceof Object;System.out.println("b1 = " + b1 + ", b2 = " + b2);}}创建B的对象时会输出?( )A: 编译失败. B: b1 = true, b2 = true C: b1 = true, b2 = falseD: b1 = false, b2 = true E: b1 = false, b2 = false21. 哪一个能通过编译?()A: new Animal().soundOff(); B: Lion l = Alpha1.get("meat eater");C: Elephant e = new Alpha1(); D: new Alpha1().get("veggie").soundOff();22. 分析:class Passenger { }class Engine { }interface TransportVehicle {void loadPassengers();}interface Helicopter extends TransportVehicle {int flyIt( String direction );}abstract class JetStream implements Helicopter { }哪种说法是正确的?()A: TransportVehicle has a Passenger. B: 类Engine在类JetStream中.C: 接口TransportVehicle可以形成多态的基础.D: 继承JetStream的非抽象类可以随意声明方法loadPassengers().23. 哪三个是"is a" 关系? ( )A:public class X { } B:public interface Shape { }public class Y extends X { } public interface Rectangle extends Shape{ }C:public interface Color { } D:public class Species { }public class Shape { private Color color; } public class Animal { private Species species; }E:public class Person { } F:interface Component { }public class Employee { class Container implementsComponent {public Employee(Person person) { } private Component[] children;} }24. 运行结果是:()public interface Test {int frood = 42;}class TestImpl implements Test {private static int frood;public static void main(String[] args) {System.out.println(++frood);}}A: 0 B: 1 C: 42 D: 43 E: 编译失败. F: 运行时异常.25. 运行结果是?()A: 5 B: 10 C: 编译失败. D: 运行时异常.26. 运行结果是:()1) public class Test {2) public static void main(String args[]) {3) class Foo {4) public int i = 3;5) }6) Object o = (Object)new Foo();7) Foo foo = (Foo)o;8) System.out.println("i = " + foo.i);9) }10) }A: i = 3 C: 第6行抛出ClassCastException异常.B: 编译失败. D: 第7行抛出ClassCastException异常.27. 分析:String s = "abcde";Object ob = (Object)s;if (ob.equals(s)) {System.out.println("AAAA");} else {System.out.println("BBBB");}if (s.equals(ob)) {System.out.println("CCCC");} else {System.out.println("DDDD");}输出哪两行? ( )A:AAAA B:BBBB C:CCCC D:DDDD二、简答题1. 简述类与类之间的关系2. 简述继承的基本概念及继承的过程3. 简述方法重写以及方法重载与方法重写的区别4. 简述super关键字的用法5. 简述重写equals方法的步骤6. 简述instanceof关键字的用法7. 简述接口和抽象类的区别8. 简述什么是多态三、编程题1. 设计一个学生类Student,包括的属性有姓名name,年龄age,学位degree。