第七章繼承多態(tài)練習題_第1頁
第七章繼承多態(tài)練習題_第2頁
第七章繼承多態(tài)練習題_第3頁
第七章繼承多態(tài)練習題_第4頁
第七章繼承多態(tài)練習題_第5頁
已閱讀5頁,還剩5頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、第七章繼承多態(tài)一、選擇題:1、分析: class A A() class B extends A /系統(tǒng)自動生成的構造方法和類的訪問權限一樣 哪兩種說法是正確的? ()A:類B的構造方法是public的. B:類B的構造方法包含對this()的調用.C:類B的構造方法沒有參數(shù). D:類B的構造方法包含對super()的調用.2、運行結果是:() class Base Base() System.out.print(Base); public class Alpha extends Base public static void main( String args ) new Alpha();

2、new Base(); A: BaseB: BaseBaseC: 編譯失敗. D: 沒有輸出.E: 運行時異常.3. 程序的運行結果是?()A: 編譯失敗.B: hello from aC: 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 Tes

3、tSub(); A: 編譯失敗.B: 程序運行沒有異常.C: 第7行拋出異常.D: 第2行拋出異常.5. 程序的運行結果是?()A: 0B: 1C: 2D: 編譯失敗.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: 1B: 2C: 第8行編譯失敗.D: 第14行編譯失敗.8. 分析: public class ConstOver public ConstOver(int x, int y, int z) 哪兩個是對ConstOver 的構造方法的重載

4、? ()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,4B: 4,5C: 5,4D: 5,5E: 編譯失敗.10. 分析: public class X public X aMethod() return this; 1) public class Y e

5、xtends 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,4B: 4,5C: 5,4D: 5,5E: 編譯失敗.12. 以下哪兩個重載了方法setVar()? () public class MethodOver public void setVar(int

6、 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

7、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 here 8) 在第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 doub

8、le 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: 1B: 2C: 運行時異常.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

9、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 me

10、thodB()5) 6) System.out.println(Hello); 7) 8) 哪兩種改法,可以使程序通過編譯? ()A:給方法methodA()加方法體C:在Test的聲明中去掉abstractB:用;替換第5-7行D:在方法methodA()的聲明中去掉abstractE: 在方法methodB()的聲明中去掉abstract17. 運行結果是:() 1) abstract class AbstractIt 2) abstract float getFloat(); 3) 4) public class AbstractTest extends AbstractIt 5) pr

11、ivate 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 =

12、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 A10; boolean b1 = this instanceof Inter; boolean b2 = arr instanceof Object; S

13、ystem.out.println(b1 = + b1 + , b2 = + b2); 創(chuàng)建B的對象時會輸出?()A: 編譯失敗.B: b1 = true, b2 = trueC: b1 = true, b2 = falseD: b1 = false, b2 = trueE: 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).sound

14、Off();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: 接口Transpor

15、tVehicle可以形成多態(tài)的基礎.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 pri

16、vate Species species; E:public class Person F:interface Component public class Employee class Container implements Component public Employee(Person person) private Component children;24. 運行結果是:() public interface Test int frood = 42; class TestImpl implements Test private static int frood; public st

17、atic void main(String args) System.out.println(+frood); A: 0B: 1C: 42D: 43E: 編譯失敗.F: 運行時異常.25. 運行結果是?()A: 5B: 10C: 編譯失敗.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) Sys

18、tem.out.println(i = + foo.i); 9) 10) A: i = 3C: 第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); 輸出哪

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論