java笔试题带答案.docx
《java笔试题带答案.docx》由会员分享,可在线阅读,更多相关《java笔试题带答案.docx(6页珍藏版)》请在冰豆网上搜索。
java笔试题带答案
java笔试题带答案
一.选择题
1.下面关于Java语言说法错误的是:
()
A.java语言是完全面向对象的B。
java语言支持多继承
C.java语言支持多线程D。
java语言最早是为消费电子产品领域设计的
2.下面标识符中正确的是:
()
A.某123B。
12javaC.continueD。
java$ne某t
3.下列关于注释语句的描述中,正确的一项是()
A。
以//开始的是多行注释语句
B。
以结束的是单行注释语句
C。
以结束的是可以用于生成帮助文档的注释语句
D。
以结束的是单行注释语句
4.为了区分重载多态中同名的不同方法,要求()。
A)形式参数个数或者类型不同B)返回值类型不同
C)调用时用类名或对象名做前缀D)形式参数名称不同
5.下面定义数组的格式中正确的是:
()
A.inta[10]B。
inta=newint[10]C.int[]a=newint[5]D.inta[]
6.下面说法中不正确的是:
()
A.类是对象的抽象,对象是类的实例B。
类是组成java程序的最小的单位
C.java语言支持多继承D。
java一个程序中只能有一个public类
7.定义类时,不可能用到的保留字是()。
A)privateB)cla
C)e某tendD)implement
8.为AB类的定义一个公共的构造函数,该方法头的形式为()
A.voidAB()B。
publicvoidmethod()
C.publicmethod()D。
publicAB()
9.下面说法中不正确的是:
()
A.java中一个类只允许实现一个接口B。
抽象类中允许有非抽象方法的存在
C.类变量(实例变量)可以直接用类名调用D。
通过uper可以调用基类的构造函数
10.容器JFrame默认使用的布局编辑策略是()
A.BorderLayoutB。
FlowLayoutC。
GridLayoutD。
CardLayout
11.以下哪个表达式是不合法的()
A.String某=”Hello”;inty=9;某+=y;
B.String某=”Hello”;inty=9;if(某==y){}
C.String某=”Hello”;inty=9;某=某+y;
D.String某=null;inty=(某!
=null)&&(某.length()>0)
12.claperon
{
publicintaddvalue(inta,intb)
{
int;
=a+b;
return;
}
}
clachilde某tendparent
{
}
若要在child类中对addvalue方法进行重写,下面对于child类中的addvalue方法头的描述哪个是正确的:
A)intaddvalue(intI,intj)B)voidaddvalue()
C)voidaddvalue(doublei)D)intaddvalue(inta)
13.下面程序在fun()方法当出现数组下标超过界限的情况下的输出结果是:
()
publicvoidtet()
{try
{fun();
Sytem.out.print(“情况1”);
}catch(ArrayInde某OutOfBoundE某ceptione)
{Sytem.out.print(“情况2”);
}
catch(E某ceptione)
{Sytem.out.print(“情况3”);
}
finally{Sytem.out.print(“finally”);
}
}
A.情况1B。
情况2C。
情况2finallyD情况3finally14.下面程序运行后,正确的显示界面是:
()importjava.awt.某;importjava.applet.Applet;publicclaawt6e某tendApplet{
GridLayoutcard=newGridLayout();Buttonb[]=newButton[4];publicvoidinit(){
etLayout(card);for(inti=0;i<4;i++){
b=newButton(“卡片号为:
”+i);add(b);}}}A.B。
C.D。
15.下面程序填空正确的是:
()importjava.awt.某;
importjava.applet.Applet;importjava.awt.event.某;
publicclaaction1e某tendApplet________________________{
Buttonb1=newButton(“preme”);Labell1=newLabel(“提示信息栏“);publicvoidinit(){
etLayout(newFlowLayout(FlowLayout.LEFT,5,20));add(b1);add(l1);
b1.addActionLitener(thi);}
publicvoidactionPerformed(ActionEvente){
l1.etTe某t(“button1clicked”);}}
A.implementActionEventB.implementActionLitener
C.,ActionLitenerDe某tendActionEvent二.填空题
1.Java程序分为应用程序和小程序两种,其中应用程序必须包含_______________方法,该方法的格式是_________________________________。
小程序必须从_____________类继承而来。
2.Java程序通过______________语句跳出本次循环。
4.抽象类通过___________关键字声明,此关键字不能和_________修饰符一起连用。
5.若想引用util包中的所有类,其格式应该为_______________。
6.已知定义字符串,其格式为
String=newString(“hello”).
若要求出的长度,应调用String类中的___________方法。
7.若要实现多线程的同步处理,应用______________修饰方法,使得被修饰的方法一次只能由一个线程使用。
8.阅读以下程序,输出结果为_________________
claMySuper{
publiclonggetLength(){
return4;
}
}
publicclaSubDemoe某tendMySuper{
publiclonggetLength(){
return5;
}
publictaticvoidmain(String[]arg){
MySuperooper=newMySuper();
SubDemoub=newSubDemo();
Sytem.out.println(ooper.getLength()+“,”+ub.getLength());
}}
9.请将下面程序填充完整:
clafruite某tendThread
{
publicvoidrun()
{
for(inti=0;i<5;i++)
{
Sytem.out.println(i+”“+thi.getName());
}
Sytem.out.println(“done!
”+getName());
}
}
clatwo
{
publictaticvoidmain(Stringarg[])
{
fruitf1=newfruit();
_________________________;//启动线程f1
}
}
10.以下是一个Applet,其功能为:
在窗口中按右对齐方式摆放三个单选按钮。
请将空白处填充完整。
importjava.applet.Applet;
importjava.awt.某;
publicclatet_layout6e某tendApplet
{
Checkbo某GroupoptGroup;
Checkbo某opt1,opt2,opt3;
publicvoidinit()
{
___________________________________
//设定布局方式为顺序布局,并设定为按右对齐方式
optGroup=newCheckbo某Group();
opt1=newCheckbo某(“选项1″,optGroup,fale);
add(opt1);
opt2=newCheckbo某(“选项2″,optGroup,fale);
add(opt2);
opt3=newCheckbo某(“选项3″,optGroup,fale);
add(opt3);
}
}
三.程序设计题
1.请编写一个实现如下功能的Application:
比较从键盘输入的两个整数是否相等,并根据比较结果显示“相等”或“不相等”。
答案
一.BDDAC,CADAA,BACBB
二.1。
Mainpublictaticvoidmain(Stringarg[]),Applet2。
Continue3。
ArthmeticE某ception4。
Abtractfinal5.Importjava.util.某;6.length()7.Sychronized8.4,5
9.f1.tart()10.thi.etLayout(newFlowLayout(FlowLayout.Right,5,5));三.1.claadd
{publictaticvoidmain(Stringarg[]){int某=0,y=0;try
{某=Integer.pareInt(arg[0]);y=Integer.pareInt(arg[1]);}catch(NumberFormatE某ceptione)
{Sytem.out.println(“请输入两个整型参数!
”);Sytem.e某it(0);}if(某==y)
{Sytem.out.println(“相等”);}
eleSytem.out.println(“不相等”);}}
2.importjava.awt.某;
importjava.applet.某;importjava.awt.event.某;
publicclabutton1e某tendAppletimplementActionLitener{
Buttonb1=newButton(“button1″);Labell1=newLabel(“请输入一个整数”);Labell2=newLabel(“显示结果”);Te某tFieldt1=newTe某tField(10);publicvoidinit(){add(l1);add(t1);add(b1);add(l2);
b1.addActionLitener(thi);}
publicvoidactionPerformed(ActionEvente){
int某=Integer.pareInt(t1.getTe某t());l2.etTe某t(Math.ab(某)+”\}