Java 笔试题含答案.docx
- 文档编号:5097513
- 上传时间:2022-12-13
- 格式:DOCX
- 页数:7
- 大小:16.70KB
Java 笔试题含答案.docx
《Java 笔试题含答案.docx》由会员分享,可在线阅读,更多相关《Java 笔试题含答案.docx(7页珍藏版)》请在冰豆网上搜索。
Java笔试题含答案
班级:
_______________学号:
______________姓名:
___________
Java笔试题
(可多选)
1.下面哪些是Thread类的方法(ABD)
Astart()Brun()Cexit()DgetPriority()
2.下面关于类的说法正确的是(A)
A继承自Throwable
BSerialable
C该类实现了Throwable接口
D该类是一个公共类
3.下面程序的运行结果是(false)
Stringstr1="hello";
Stringstr2="he"+newString("llo");
==str2);
4.下列说法正确的有(C)
A.class中的constructor不可省略
B.constructor必须与class同名,但方法不能与class同名
C.constructor在一个对象被new时执行
D.一个class只能定义一个constructor
5.指针在任何情况下都可进行>,<,>=,<=,==运算(true)
6.下面程序的运行结果:
(B)
publicstaticvoidmain(Stringargs[]){
Threadt=newThread(){
publicvoidrun(){
pong();
}
};
();
"ping");
}
staticvoidpong(){
"pong");
}
Apingpong
Bpongping
Cpingpong和pongping都有可能
D都不输出
7.下列属于关系型数据库的是(AB)
A.OracleBMySqlCIMSDMongoDB
8.GC(垃圾回收器)线程是否为守护线程(true)
9.volatile关键字是否能保证线程安全(false)
10.下列说法正确的是(AC)
ALinkedList继承自List
BAbstractSet继承自Set
CHashSet继承自AbstractSet
DWeakMap继承自HashMap
11.存在使i+1
12.的数据类型是(B)
AfloatBdoubleCFloatDDouble
13.下面哪个流类属于面向字符的输入流(A)
ABufferedWriter
BFileInputStream
CObjectInputStream
DInputStreamReader
14.Java接口的修饰符可以为(CD)
AprivateBprotectedCfinalDabstract
15.不通过构造函数也能创建对象吗(A)
A是B否
16.ArrayListlist=newArrayList(20);中的list扩充几次(A)
A0B1C2D3
17.下面哪些是对称加密算法(AB)
ADESBAESCDSADRSA
18.新建一个流对象,下面哪个选项的代码是错误的(B)
A)newBufferedWriter(newFileWriter(""));
B)newBufferedReader(newFileInputStream(""));
C)newGZIPOutputStream(newFileOutputStream(""));
D)newObjectInputStream(newFileInputStream(""));
19.下面程序能正常运行吗(yes)
publicclassNULL{
publicstaticvoidhaha(){
"haha");
}
publicstaticvoidmain(String[]args){
((NULL)null).haha();
}
}
20.下面程序的运行结果是什么()
classHelloA{
publicHelloA(){
"HelloA");
}
{"I'mAclass");}
static{"staticA");}
}
publicclassHelloBextendsHelloA{
publicHelloB(){
"HelloB");
}
{"I'mBclass");}
static{"staticB");}
publicstaticvoidmain(String[]args){
newHelloB();
}
}
StaticA
StaticB
HelloA
I’mAclass
HelpB
I’mBClass
21.getCustomerInfo()方法如下,try中可以捕获三种类型的异常,如果在该方法运行中产生了一个IOException,将会输出什么结果(A)
publicvoidgetCustomerInfo(){
try{
下面代码的运行结果为:
(C)
import.*;
import.*;
publicclassfoo{
publicstaticvoidmain(String[]args){
Strings;
"s="+s);
}
}
A代码得到编译,并输出“s=”
B代码得到编译,并输出“s=null”
C由于Strings没有初始化,代码不能编译通过
D代码得到编译,但捕获到NullPointException异常
23."5"+2);的输出结果应该是(A)。
A52B7C2D5
24.指出下列程序运行的结果(B)
publicclassExample{
Stringstr=newString("good");
char[]ch={'a','b','c'};
publicstaticvoidmain(Stringargs[]){
Exampleex=newExample();
;
+"and");
}
publicvoidchange(Stringstr,charch[]){
str="testok";
ch[0]='g';
}
}
A、goodandabc
B、goodandgbc
C、testokandabc
D、testokandgbc
25.要从文件""中读出第10个字节到变量c中,下列哪个方法适合(AB)
AFileInputStreamin=newFileInputStream("");(9);intc=();
BFileInputStreamin=newFileInputStream("");(10);intc=();
CFileInputStreamin=newFileInputStream("");intc=();
DRandomAccessFilein=newRandomAccessFile("");(9);intc=();
26.下列哪种异常是检查型异常,需要在编写程序时声明(C)
ANullPointerException
BClassCastException
CFileNotFoundException
DIndexOutOfBoundsException
27.下面的方法,当输入为2的时候返回值是多少(D)
publicstaticintgetValue(inti){
intresult=0;
switch(i){
case1:
result=result+i;
case2:
result=result+i*2;
case3:
result=result+i*3;
}
returnresult;
}
A0B2C4D10
Switch也需要Break
28.选项中哪一行代码可以替换题目中阅读Shape和Circle两个类的定义。
在序列化一个Circle的对象circle到文件时,下面哪个字段会被保存到文件中(B)
classShape{
publicStringname;
}
classCircleextendsShapeimplementsSerializable{
privatefloatradius;
transientintcolor;
publicstaticStringtype="Circle";
}
Aname
Bradius
Ccolor
Dtype
父类为继承Serializable接口,其成员不能被序列化,静态变量和transient修饰的不能被序列化
30.下面是People和Child类的定义和构造方法,每个构造方法都输出编号。
在执行newChild("mike")的时候都有哪些构造方法被顺序调用请选择输出结果(D)
classPeople{
Stringname;
publicPeople(){
}
publicPeople(Stringname){
=name;
}
}
classChildextendsPeople{
Peoplefather;
publicChild(Stringname){
=name;
father=newPeople(name+":
F");
}
publicChild(){
}
}
A312B32C432D132
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 笔试题含答案 笔试 答案