JAVA面向对象基础测试题继承封装多态等测试题Word格式文档下载.docx

上传人:b****0 文档编号:13318860 上传时间:2022-10-09 格式:DOCX 页数:18 大小:17.32KB
下载 相关 举报
JAVA面向对象基础测试题继承封装多态等测试题Word格式文档下载.docx_第1页
第1页 / 共18页
JAVA面向对象基础测试题继承封装多态等测试题Word格式文档下载.docx_第2页
第2页 / 共18页
JAVA面向对象基础测试题继承封装多态等测试题Word格式文档下载.docx_第3页
第3页 / 共18页
JAVA面向对象基础测试题继承封装多态等测试题Word格式文档下载.docx_第4页
第4页 / 共18页
JAVA面向对象基础测试题继承封装多态等测试题Word格式文档下载.docx_第5页
第5页 / 共18页
点击查看更多>>
下载资源
资源描述

JAVA面向对象基础测试题继承封装多态等测试题Word格式文档下载.docx

《JAVA面向对象基础测试题继承封装多态等测试题Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《JAVA面向对象基础测试题继承封装多态等测试题Word格式文档下载.docx(18页珍藏版)》请在冰豆网上搜索。

JAVA面向对象基础测试题继承封装多态等测试题Word格式文档下载.docx

09

p.step(10);

10

11

}

A.14

B.20

C.10

D.17

正确答案:

B解析:

2.

程序的执行结果是:

publicclassQuestion{

privateintnum;

publicstaticvoidmain(String[]args){

Questionq=newQuestion();

q.num=13;

update(q);

publicstaticvoidupdate(Questionq){

q.num=9;

12

A.13

B.9

C.0

D.4

3.

publicclassAnswer{

intscore=20;

Answerans=newAnswer();

ans.add(score);

"

main:

score="

+score);

voidadd(intscore){

add:

score="

+score++);

A.

1

add:

score=21

2

score=21

B.

score=20

C.

score=20

D.

D解析:

4.

下列代码编译或运行的结果是:

publicclassSnow{

publicStringjump(intx,inty){

return"

jumpone"

;

publicStringjump(int[]vals){

jumptwo"

Snows=newSnow();

5));

A.publicStringjump(int[]vals){行,编译出错

行,抛出运行时异常

C.输出:

jumpone

D.输出:

jumptwo

C解析:

5.

关于下列代码说法正确的是:

publicclassStorm{

publicvoidfind(){

publicStringfind(){

find"

publicdoublefind(intx){

return2.0;

A.无编译错误

B.代码publicStringfind(){行,出现编译错误

C.代码publicdoublefind(intx){行,出现编译错误

D.代码return"

行处出现编译错误

6.

请看下列代码:

classClassA{}

classClassBextendsClassA{}

classClassCextendsClassA{}

publicclassTest{

ClassAp0=newClassA();

ClassBp1=newClassB();

ClassCp2=newClassC();

ClassAp3=newClassB();

ClassAp4=newClassC();

<

插入代码>

13

下列选项中放置在<

处,使程序编译正确的是:

A.p0=p1;

B.p1=p2;

C.p2=p4;

D.p2=(ClassC)p1;

A解析:

7.

下列代码的运行结果是:

publicclassAnimal{

publicStringnoise(){

Animal"

Catcat=null;

Animalanimal=newDog();

if(animalinstanceofCat){

cat=(Cat)animal;

}else{

animalisnotCat'

sinstance"

);

14

15

16

classDogextendsAnimal{

17

18

Dog"

19

20

21

classCatextendsAnimal{

22

23

Cat"

24

25

A.Animal

B.Dog

C.Cat

D.animalisnotCat'

sinstance

8.

请看下列代码编译和运行的结果是:

publicclassTeacher{

privateStringname="

sun"

3

4

Teacher[]teachers=newTeacher[2];

5

6

7

8

A.sun2

B.null2

C.null1

D.运行时抛出NullPointerException异常

9.

下列代码编译和运行的结果是:

classPerson{

Stringname="

publicPerson(Stringname){

this.name=name;

classEmployeeextendsPerson{

StringempNO="

0000"

publicEmployee(StringempNO){

this.empNO=empNO;

publicclassEmployeeTest{

Employeee=newEmployee("

1109"

A.输出:

0000

B.输出:

1109

C.代码publicEmployee(StringempNO){行,出现编译错误

D.抛出运行时异常

10.

classA{

publicvoidstart(){

AStart"

publicclassBextendsA{

BStart"

((A)newB()).start();

AStart

BStart

AStartBStart

D.编译错误

11.

publicinterfaceA{

publicvoiddoSomething(Stringthing);

interfaceB{

interfaceCextendsA,B{

interfaceD{

publicvoiddoIt(Stringthing);

classAImplimplementsC,D{

publicvoiddoSomething(Stringmsg){}

publicvoiddoIt(Stringthing){}

A.所有类和接口都编译成功

B.接口A编译失败

C.类AImpl编译失败

D.接口C编译失败

12.

在Java中,关于final关键字的说法正确的是:

A.如果修饰局部变量,必须定义时初始化

B.如果修饰类,则该类只能被一个子类继承

C.如果修饰方法,则该方法不能在子类中被覆盖

D.如果修饰方法,则该方法所在的类不能被继承

13.

publicclassCell{

privatefinalintid;

publicCell(intid){

this.id=id;

publicvoidupdateId(intid){

Cellc

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医药卫生 > 药学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1