尾部都有答案
第七章練習(xí)題(多態(tài))
(1)下列自‘關(guān)多態(tài)的敘述正確的是哪項(xiàng)?(選兩項(xiàng))
A. 父類的引用指向子類的實(shí)例是一種多態(tài)
B. 子類的引用指向子類的實(shí)例是一種多態(tài)
C. 接口的引用指向?qū)崿F(xiàn)該接口類的實(shí)例是一種多態(tài)
D. 抽象類的引用指向抽象類的實(shí)例是一種多態(tài)
(2)Java中方法綁定有哪些形式纤房?(選兩項(xiàng))
A. 編譯時(shí)刻綁定
B. 運(yùn)行時(shí)刻綁定
C. 靜態(tài)綁定
D. 私有綁定
(3)表達(dá)式"hello" instance of String返回的值是哪項(xiàng)却嗡?
A. true
B. false
C. 1
D. 0
(4)求平方根方法public static double sqrt (double a)可以傳遞的參數(shù) 類型有哪些次伶?(選三項(xiàng))
A. byte
B. float
C. String
D. long
(5)涉及類MyClass的方法簽名足public void find(MyClass a),那么該方法可接收的實(shí)際參數(shù)的類型可以是哪些稽穆?(選兩項(xiàng))
A. MyClass類的類型
B. MyClass子類的類型
C. Object類型
D.所有接口
(6)使用下列哪些關(guān)鍵字可以判定實(shí)參的具體類型?
A. as
B. is
C. instanceof
D. extends
(7)現(xiàn)有
Class Pencil {
public void write (String content){
System.out.println ("Write"+content);
}
}
Class RubberPencil extends Pencil{
public void erase (String content){
System.out.println ("Erase"+content);
}
}
執(zhí)行下列代碼的結(jié)果是哪項(xiàng)赶撰?
Pencil pen=new RubberPencil();
pen.write ("Hello")舌镶;
pen.erase ("Hello");
A. Write Hello
Erase Hello
B. Erase Hello
Write Hello
C. 編譯錯(cuò)誤
D. 運(yùn)行時(shí)拋出異常
(8)現(xiàn)有
Class Pencil {
public void write (String content){
System.out.println ("Write"+content)柱彻;
}
}
Class RubberPencil extends Pencil{
public void write (String content){
System.out.println ("Rubber Write"+content);
}
public void erase (String content){
System.out.println ("Erase "+content);
}
}
執(zhí)行下列代碼的結(jié)果是哪項(xiàng)?
Pencil pen=new RubberPencil()餐胀;
pen.write("Hello")哟楷;
A. Write Hello
B. Rubber Write Hello
C. 編譯錯(cuò)誤
D. 運(yùn)行時(shí)拋出異常
(9)下列哪些方法是在編譯時(shí)刻綁定的?(選三項(xiàng))
A.靜態(tài)方法
B. private方法
C.final方法
D.非private方法
(10)現(xiàn)有
Class Pencil {
public void write (String content){
System.out.println( "Write",+content){
}
}
Class RubberPencil extends Pencil{
public void write (String content){
System.out.println("Rubber Write"+content)否灾;
}
public void erase (String content){
System.out.println( "Erase "+content);
}
}
執(zhí)行下列代碼的結(jié)果是哪項(xiàng)卖擅?
Pencil pen=new Pencil();
(( RubberPencil) pen).write( "Hello");
A. Write Hello
B. Rubber Write Hello
C. 編譯失敗
D. 運(yùn)行時(shí)拋出異常
(11)現(xiàn)有
Class TestA {
public void start() { System.out.println("TestA"); }
}
public class TestB extends TestA {
public void start() { System.out.println("TestB"); }
public static v.id main(string[] args) (
((TestA)new TestB()).start();
}
}
運(yùn)行結(jié)果是哪項(xiàng)?
A. TeStA
B. TeStB
C. 編譯失敗
D. 運(yùn)行時(shí)拋出異常
(12)現(xiàn)有
Class A {public String name="a"}
Class B extends A {public String name="b"}
a = new B()墨技;
System.out.println(a.name);
執(zhí)行如上代碼后的結(jié)果是哪項(xiàng)惩阶?
A. a
B. b
C. 編譯失敗
D. 運(yùn)行時(shí)拋出異常
(13)現(xiàn)有
Interface F {}
class A implements F {}
class B extends A {}
class C extends B {
public static void main(String[] args){
B b=new B();
//inSert C0de here
}
}
下列哪行代碼插入到第7行扣汪,將拋出java.lang.ClassCaseException異常断楷?
A. A a=b;
B. F f = (C)b;
C. F f = (A)b崭别;
D. B bb = (B)(A)b冬筒;
(14)現(xiàn)有
class Guy { String greet() { return "hi"; } }
class Cowboy extends Guy { String greet() { return. "howdy";}}
class Wrangler extends Cowboy { String greet() { return "orch!"; } }
class Greetings2 {
public static void main (String [] args) {
Guy g=new Wrangler();
Guy g2=new Cowboy();
Wrangler w2=new Wrangler();
System. out .print (g.greet()+g2.greet()+w2 .greet())茅主;
}
}
結(jié)果是什么舞痰?
A. hi hi ouch!
B. ouch! howdy ouch!
C. hi howdy ouch!
D. 編譯失敗
E. 運(yùn)行的咐候有異常拋出
(15)現(xiàn)有
Class ClassA {}
Class ClassB extends ClassA {)
Class ClassC extends ClassA {)
//以及
ClassA p0 = new ClassA();
ClassB pl = new ClassB();
ClassC p2 = new ClassC()诀姚;
ClassA p3 = new ClassB()响牛;
ClassA p4 = new ClassC();
下列哪些是正確的学搜?(選三項(xiàng))
A. p0=pl;
B. p1 =p2;
C. p2=p4;
D. p2 = (ClassC)pl;
E. p1 = (ClassB)p3;
F. p2 = (Classc)p4;
參考答案
1娃善、AC
2、AB
3瑞佩、A
4聚磺、ABD
5、AB
6炬丸、C
7瘫寝、C
8、B
9稠炬、ABC
10焕阿、D
11、B
12首启、A
13暮屡、B
14、B
15毅桃、AEF