第六章判断题面向对象1.docx

上传人:b****6 文档编号:16811712 上传时间:2023-07-17 格式:DOCX 页数:13 大小:18.02KB
下载 相关 举报
第六章判断题面向对象1.docx_第1页
第1页 / 共13页
第六章判断题面向对象1.docx_第2页
第2页 / 共13页
第六章判断题面向对象1.docx_第3页
第3页 / 共13页
第六章判断题面向对象1.docx_第4页
第4页 / 共13页
第六章判断题面向对象1.docx_第5页
第5页 / 共13页
第六章判断题面向对象1.docx_第6页
第6页 / 共13页
第六章判断题面向对象1.docx_第7页
第7页 / 共13页
第六章判断题面向对象1.docx_第8页
第8页 / 共13页
第六章判断题面向对象1.docx_第9页
第9页 / 共13页
第六章判断题面向对象1.docx_第10页
第10页 / 共13页
第六章判断题面向对象1.docx_第11页
第11页 / 共13页
第六章判断题面向对象1.docx_第12页
第12页 / 共13页
第六章判断题面向对象1.docx_第13页
第13页 / 共13页
亲,该文档总共13页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

第六章判断题面向对象1.docx

《第六章判断题面向对象1.docx》由会员分享,可在线阅读,更多相关《第六章判断题面向对象1.docx(13页珍藏版)》请在冰点文库上搜索。

第六章判断题面向对象1.docx

第六章判断题面向对象1

第六章判断题

1.构造方法用于给类的private实例变量赋值。

()

2.在定义变量和方法时,必须清楚地在起面前标上访问权限修饰符。

()

3.在类定义中,成员访问权限修饰符不能多次出现。

()

4.通过点运算符与类对象的引用相连,可以访问此类的成员。

()

5.声明为protected的类成员只能被次类中的方法访问。

()

6.类的方法通常设为public,而类的实例变量一般设也为public。

()

7.类定义以关键字extends开始。

()

8.声明为protected的类成员可以被此类作用域中的任何对象访问。

()

9.new操作符动态地为对象按其指定的类型分配内存,并返回该类型的一个引用。

()

10.public实例变量代表类范围的信息。

()

第六章选择题

1.下面那一个不是Java的关键字:

A.TRUE

B.sizeof

C.const

D.super

E.void

2.请看下面的程序段

classPerson{

Stringname,department;

intage;

publicPerson(Stringn){name=n;}

publicPerson(Stringn,inta){name=n;age=a;}

publicPerson(Stringn,Stringd,inta){

//doingthesameastwoargumentsversionofconstructer

//includingassignmentname=n,age=a

}

}

下面那一选项可以添加到“//doingthesame……”处:

A.Person(n,a)

B.this(Person(n,a))

C.this(n,a)

D.this(name.age)

3.▁▁是一个特殊的方法,用于对类的实例变量进行初始化。

A.终止函数

B.构造函数

C.重载函数

D.初始化函数

4.关于变量和它们范围的说法,正确的是:

A.实例变量是类的成员变量

B.实例变量要用关键字static来声明

C.在一个方法执行时,定义在该方法的局部变量才被创建

D.局部变量必须在它们使用前初始化

5.请看下面的程序段

classTest{

privateintm;

publicstaticvoidfun(){

//somecode…

}

}

方法fun()如何来访问变量m:

A.将privateintm改成protectedintm

B.将privateintm改成publicintm

C.将privateintm改成staticintm

D.将privateintm改成intm

6.在Java中,方法main()将返回一个▁▁值。

A.String

B.int

C.char

D.void

7.请看下面的程序段

inti=1;

intj;

j=i++

在程序段运行后,i和j的值为:

A.1,1

B.1,2

C.2,1

D.2,2

8.请看下面的程序段

publicclassTest{

longa[]=newlong[10];

publicstaticvoidmain(Stringarg[]){

System.out.println(a[6]);

}

}

那一个选项是正确的:

A.不输出任何内容

B.输出0

C.当编译时有错误出现

D.当运行时有错误出现

9.关键字▁▁表明一个对象或变量在初始化后不能修改。

A.extends

B.final

C.this

D.finalizer

10.声明为static的方法不能访问▁▁类成员。

A.超类

B.子类

C.非static

D.用户自定义类

第六章程序设计题

1.编写一个Java程序片断定义一个表示学生的类student,包括域“学号”、“班号”、“姓名”、“性别”、“年龄”、方法“获得班号”、“获得性别”、“获得姓名”、“获得年龄”、“修改年龄”。

2.在上题的基础上编写JavaApplication程序创建Student类的对象。

3.为Student类定义构造函数初始化所有的域,增加一个方法publicStringtoString()把Student类对象的所有域信息组合成一个字符串。

编写Application程序检验新增的功能。

4.编写一个Applet程序,接受用户输入的卡号、密码、金额和接入号码,创建PhoneCard类的对象并输出这张电话卡的有关信息。

第六章判断题答案

1.难度:

容易

答案:

错误

知识点:

设置方法用于给类的private实例变量赋值。

2.难度:

容易

答案:

正确

知识点:

对变量和方法的定义。

3.难度:

容易

答案:

错误

知识点:

在类定义中,成员访问权限修饰符可以多次出现,而且出现的次序不限。

4.难度:

容易

答案:

正确

知识点:

点运算符的使用。

5.难度:

适中

答案:

错误

知识点:

声明为private的类成员只能被次类中的方法访问。

6.难度:

容易

答案:

错误

知识点:

类的实例变量一般设为private。

7.难度:

容易

答案:

正确

知识点:

关键字extends的使用。

8.难度:

容易

答案:

错误

知识点:

声明为public的类成员可以被此类作用域中的任何对象访问。

9.难度:

容易

答案:

正确

知识点:

new操作符的使用。

10.难度:

适中

答案:

错误

知识点:

static实例变量代表类范围的信息。

第六章选择题答案

1.难度:

容易

答案:

AB

知识点:

在Java中,ture和false都是小写,并且没有sizeof这样的关键字。

2.难度:

适中

答案:

C

知识点:

this引用的使用。

3.难度:

适中

答案:

B

知识点:

构造函数是一个特殊的方法,用于对类的实例变量进行初始化。

4.难度:

适中

答案:

ACD

知识点:

声明类时用关键字static。

5.难度:

适中

答案:

C

知识点:

将变量m改成staticintm是因为方法fun()是静态的。

6.难度:

容易

答案:

D

知识点:

方法main()只能返回一个空值。

7.难度:

容易

答案:

C

知识点:

++操作符的使用。

8.难度:

适中

答案:

B

知识点:

数组初始化后,其所有元素的值为0。

9.难度:

容易

答案:

B

知识点:

关键字final表明一个对象或变量在初始化后不能修改。

10.难度:

适中

答案:

C

知识点:

声明为static的方法不能访问非static类成员。

第六章程序设计题答案

1.难度:

适中

答案:

源程序:

Student.java

classStudent

{

privateStringstudentId;

privateintclassId;

privateStringstudentName;

privatecharstudentGender;

privateintstudentAge;

StringgetStudentId()

{

returnstudentId;

}

intgetclassId()

{

returnclassId;

}

chargetStudentGender()

{

returnstudentGender;

}

StringgetStudentName()

{

returnstudentName;

}

intgetStudentAge()

{

returnstudentAge;

}

chargetStudentAge()

{

returnstudentAge;

}

booleansetStudentAge(intnewAge)

{

if(newAge>0&&newAge<130)

{

studentAge=newAge;

returntrue;

}

else

{

System.out.println(“非法学生年龄”);

Returnfalse;

}

}

}

知识点:

如何创建类”。

2.难度:

适中

答案:

源程序:

Chuangjian.java

publicclassChuangjian

{

publicstaticvoidmain(Stringargs[])

{

StudentdemoStudent=newStudent();

}

}

classStudent

{

privateStringstudentId;

privateintclassId;

privateStringstudentName;

privatecharstudentGender;

privateintstudentAge;

StringgetStudentId()

{

returnstudentId;

}

intgetClassId()

{

returnclassId;

}

chargetStudentGender()

{

returnstudentGender;

}

StringgetStudentName()

{

returnstudentName;

}

intgetStudentAge()

{

returnstudentAge;

}

booleansetStudentAge(intnewAge)

{

if(newAge>0&&newAge<130)

{

studentAge=newAge;

returntrue;

}

else

{

System.out.println("非法学生年龄!

");

returnfalse;

}

}

}

知识点:

创建类的对象。

3.难度:

适中

答案:

源程序:

Chuangj.java

publicclassChuangj

{

publicstaticvoidmain(Stringargs[])

{

StudentdemoStudent=newStudent("008",892,'m',"张散",19);

System.out.println(demoStudent.toString());

}

}

classStudent

{

privateStringstudentId;

privateintclassId;

privateStringstudentName;

privatecharstudentGender;

privateintstudentAge;

StringgetStudentId()

{

returnstudentId;

}

intgetClassId()

{

returnclassId;

}

chargetStudentGender()

{

returnstudentGender;

}

StringgetStudentName()

{

returnstudentName;

}

intgetStudentAge()

{

returnstudentAge;

}

booleansetStudentAge(intnewAge)

{

if(newAge>0&&newAge<130)

{

studentAge=newAge;

returntrue;

}

else

{

System.out.println("非法学生年龄!

");

returnfalse;

}

}

Student(Stringid,intclsId,chargender,Stringname,intage)

{

studentId=id;

//studentId=newString(id);

classId=clsId;

studentName=newString(name);

studentAge=age;

studentGender=gender;

}

publicStringtoString()

{

return"学生信息:

\n"+"学号"+this.getStudentId()+"\t班号"+this.getClassId()+"\t姓名"+this.getStudentName()+"\t性别"+((this.getStudentGender())=='m'?

"男":

"女")+"\t年龄"+this.getStudentAge();

}

}

知识点:

为类定义构造函数。

4.难度:

答案:

源程序:

Yonghu.java

importjava.applet.*;

importjava.awt.*;

importjava.awt.event.*;

publicclassYonghuextendsAppletimplementsActionListener

{

LabelnumberPrompt;

LabelpasswordPrompt;

LabelbalancePrompt;

LabelconnectNumberPrompt;

TextFieldnumberTfd;

TextFieldpasswordTfd;

TextFieldbalanceTfd;

TextFieldconnectNumberTfd;

TextAreainfoSummary;

ButtoncreatePhoneCardBtn;

PhoneCardmyCard;

publicvoidinit()

{

numberPrompt=newLabel("卡号");

passwordPrompt=newLabel("密码");

balancePrompt=newLabel("余额");

connectNumberPrompt=newLabel("接入号码");

numberTfd=newTextField(10);

passwordTfd=newTextField(5);

passwordTfd.setEchoChar('*');

balanceTfd=newTextField(5);

connectNumberTfd=newTextField(5);

infoSummary=newTextArea(8,30);

createPhoneCardBtn=newButton("创建");

add(numberPrompt);

add(numberTfd);

add(passwordPrompt);

add(passwordTfd);

add(balancePrompt);

add(balanceTfd);

add(connectNumberPrompt);

add(connectNumberTfd);

add(createPhoneCardBtn);

add(infoSummary);

createPhoneCardBtn.addActionListener(this);

}

publicvoidactionPerformed(ActionEvente)

{

try

{

myCard=newPhoneCard(Long.parseLong(numberTfd.getText()),Integer.parseInt(passwordTfd.getText()),Double.parseDouble(balanceTfd.getText()),connectNumberTfd.getText());

infoSummary.setText(myCard.toString());

}

catch(NumberFormatExceptionnfe)

{

infoSummary.setText("输入数据格式错误,请重试。

");

numberTfd.setText("");

passwordTfd.setText("");

balanceTfd.setText("");

connectNumberTfd.setText("");

}

}

}

classPhoneCard

{

longcardNumber;

privateintpassword;

doublebalance;

StringconnectNumber;

booleanconnected;

PhoneCard(longcn,intpw,doubleb,Strings)

{

cardNumber=cn;

password=pw;

if(b>0)

balance=b;

else

System.exit

(1);

connectNumber=s;

connected=false;

}

booleanperformConnection(longcn,intpw)

{

if(cn==cardNumber&&pw==password)

{

connected=true;

returntrue;

}

else

{

connected=false;

returnfalse;

}

}

doublegetBalance()

{

if(connected)

returnbalance;

else

return-1;

}

voidperformDial()

{

if(connected)

balance-=0.5;

}

publicStringtoString()

{

Strings="电话卡接入号码:

"+connectNumber+"\n电话卡卡号:

"+cardNumber+"\n电话卡密码:

"+password+"\n剩余金额:

"+balance;

if(connected)

return(s+"\n电话已接通。

");

else

return(s+"\n电话未接通。

");

}

}

知识点:

this引用的使用。

 

欢迎您的下载,

资料仅供参考!

 

致力为企业和个人提供合同协议,策划案计划书,学习资料等等

打造全网一站式需求

 

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

当前位置:首页 > 经管营销 > 经济市场

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2