1考java基础.docx
《1考java基础.docx》由会员分享,可在线阅读,更多相关《1考java基础.docx(58页珍藏版)》请在冰豆网上搜索。
1考java基础
一、单选(30小题共60.0分)
1.类A,B的定义如下:
classA{
privateinta=100;
A(){
System.out.print("A()");
System.out.println(a);
}
}
classBextendsA{
privateinta=200;
B(){
System.out.print("B()");
System.out.println(a);
}
}
运行下面的代码:
newB();
输出的结果是:
()。
A.
A()100
B()200
B.
A()200
B()200
C.
B()200
A()100
D.
B()200
A()200
2.
下列代码编译和运行的结果是:
publicstaticvoidmain(String[]args){
Floatpi=newFloat(3.14f);
if(pi>3){
System.out.print("piisbiggerthan3.");
}else{
System.out.print("piisnotbiggerthan3.");
}
finally{
System.out.println("Haveaniceday.");
}
}
A.
编译失败
B.
输出:
piisbiggerthan3.
C.
输出:
piisbiggerthan3.Haveaniceday
D.
输出:
piisnotbiggerthan3.Haveaniceday.
3.
下列属于不合法Java标识符的是()。
A.
_mem
B.
12a
C.
M12
D.
$12
4.
下列代码的运行结果是:
Stringtest="TestA.TestB.TestC.";
Stringregex="\\.\\s*";
String[]result=test.split(regex);
for(Strings:
result)
System.out.print(s+"");
A.
TestATestBTestC
B.
TestA.TestB.TestC.
C.
Test.Test.Test.
D.
A. B. C.
5.
类Super及Sub定义如下:
publicclassSuper{
privatevoidf(){
System.out.println("Super.f()");
}
publicvoidg(){
f();
}
publicvoidk(){
f();
}
}
publicclassSubextendsSuper{
privatevoidf(){
System.out.println("Sub.f()");
}
publicvoidk(){
f();
}
}
运行下列语句:
Superobj=newSub();
obj.g();
obj.k();
输出的结果是:
()。
A.
Sub.f()
Sub.f()
B.
Sub.f()
Super.f()
C.
Super.f()
Sub.f()
D.
Super.f()
Super.f()
6.
下列代码的运行结果是()。
publicclassForestimplementsSerializable{
privateTreetree=newTree();
publicstaticvoidmain(String[]args){
Forestf=newForest();
try{
FileOutputStreamfs=newFileOutputStream("Forest.ser");
ObjectOutputStreamos=newObjectOutputStream(fs);
os.writeObject(f);
os.close();
}catch(Exceptionex){
ex.printStackTrace();
}
}
}
classTree{}
A.
编译失败
B.
运行时,抛出异常
C.
Forest的实例被序列化到文件
D.
Forest的实例和Tree的实例都被序列化到文件
7.
运行下列代码,输出为false的是:
()。
A.
Stringst1="abc";
System.out.println("abc"==st1);
B.
Stringst2="abc";
System.out.println(st2.equals(newString("abc")));
C.
Integeri=100;
System.out.println(100==i);
D.
ArrayListlist=newArrayList();
System.out.println(list.contains(null));
8.
类A,B和C的定义如下:
publicclassA{
publicvoidf(){
System.out.println("A.f()");
}
}
publicclassBextendsA{
publicvoidf(){
System.out.println("B.f()");
}
}
publicclassC{
publicvoidg(Aa){
System.out.println("g(Aa)");
a.f();
}
publicvoidg(Bb){
System.out.println("g(Bb)");
b.f();
}
}
运行下面程序:
Cc=newC();
Aa=newB();
c.g(a);
输出的结果是:
()。
A.
g(Aa)
A.f()
一、单选(30小题共60.0分)
1.
类A,B的定义如下:
classA{
privateinta=100;
A(){
System.out.print("A()");
System.out.println(a);
}
}
classBextendsA{
privateinta=200;
B(){
System.out.print("B()");
System.out.println(a);
}
}
运行下面的代码:
newB();
输出的结果是:
()。
A.
A()100
B()200
B.
A()200
B()200
C.
B()200
A()100
D.
B()200
A()200
2.
下列代码编译和运行的结果是:
publicstaticvoidmain(String[]args){
Floatpi=newFloat(3.14f);
if(pi>3){
System.out.print("piisbiggerthan3.");
}else{
System.out.print("piisnotbiggerthan3.");
}
finally{
System.out.println("Haveaniceday.");
}
}
A.
编译失败
B.
输出:
piisbiggerthan3.
C.
输出:
piisbiggerthan3.Haveaniceday
D.
输出:
piisnotbiggerthan3.Haveaniceday.
3.
下列属于不合法Java标识符的是()。
A.
_mem
B.
12a
C.
M12
D.
$12
4.
下列代码的运行结果是:
Stringtest="TestA.TestB.TestC.";
Stringregex="\\.\\s*";
String[]result=test.split(regex);
for(Strings:
result)
System.out.print(s+"");
A.
TestATestBTestC
B.
TestA.TestB.TestC.
C.
Test.Test.Test.
D.
A. B. C.
5.
类Super及Sub定义如下:
publicclassSuper{
privatevoidf(){
System.out.println("Super.f()");
}
publicvoidg(){
f();
}
publicvoidk(){
f();
}
}
publicclassSubextendsSuper{
privatevoidf(){
System.out.println("Sub.f()");
}
publicvoidk(){
f();
}
}
运行下列语句:
Superobj=newSub();
obj.g();
obj.k();
输出的结果是:
()。
A.
Sub.f()
Sub.f()
B.
Sub.f()
Super.f()
C.
Super.f()
Sub.f()
D.
Super.f()
Super.f()
6.
下列代码的运行结果是()。
publicclassForestimplementsSerializable{
privateTreetree=newTree();
publicstaticvoidmain(String[]args){
Forestf=newForest();
try{
FileOutputStreamfs=newFileOutputStream("Forest.ser");
ObjectOutputStreamos=newObjectOutputStream(fs);
os.writeObject(f);
os.close();
}catch(Exceptionex){
ex.printStackTrace();
}
}
}
classTree{}
A.
编译失败
B.
运行时,抛出异常
C.
Forest的实例被序列化到文件
D.
Forest的实例和Tree的实例都被序列化到文件
7.
运行下列代码,输出为false的是:
()。
A.
Stringst1="abc";
System.out.println("abc"==st1);
B.
Stringst2="abc";
System.out.println(st2.equals(newString("abc")));
C.
Integeri=100;
System.out.println(100==i);
D.
ArrayListlist=newArrayList();
System.out.println(list.contains(null));
8.
类A,B和C的定义如下:
publicclassA{
publicvoidf(){
System.out.println("A.f()");
}
}
publicclassBextendsA{
publicvoidf(){
System.out.println("B.f()");
}
}
publicclassC{
publicvoidg(Aa){
System.out.println("g(Aa)");
a.f();
}
publicvoidg(Bb){
System.out.println("g(Bb)");
b.f();
}
}
运行下面程序:
Cc=newC();
Aa=newB();
c.g(a);
输出的结果是:
()。
A.
g(Aa)
A.f()
B.
g(Aa)
B.f()
C.
g(Bb)
A.f()
D.
g(Bb)
B.f()
9.
运行下面的程序:
Calendarc=Calendar.getInstance();
c.set(Calendar.YEAR,2012);
c.set(Calendar.MONTH,Calendar.SEPTEMBER);
c.set(Calendar.DATE,31);
SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-dd");
System.out.println(sdf.format(c.getTime()));
输出的结果是:
()。
A.
2012-10-1
B.
2012-10-01
C.
2012-09-30
D.
2012-9-30
10.
请看下列代码编译和运行的结果是()。
interfaceDeclareStuff{
publicstaticfinalintEASY=3;
voiddoStuff(intt);
}
publicclassTestDeclareimplementsDeclareStuff{
publicstaticvoidmain(String[]args){
intx=5;
newTestDeclare().doStuff(++x);
}
voiddoStuff(ints){
s+=EASY+++s;
System.out.println("s="+s);
}
}
A.
s=14
B.
s=16
C.
s=10
D.
编译失败
11.
需要读取一个比较大的文本文件,这个文件里有很多字节的数据,那么下列最合适读这个文件的选项是:
()。
A.
newFileInputStream(“fileName”);
B.
newInputStreamReader(newFileInputStream(“fileName”));
C.
newBufferedReader(newInputStreamReader(newFileInputStream(“fileName”)));
D.
newRandomAccessFile(“fileName”,”+rw”);
12.
请看下列代码:
publicstaticvoidmain(String[]args){
Dated=newDate(0);
Stringds="December15,2004";
<插入代码1>
DateFormatdf=DateFormat.getDateInstance();
try{
d=df.parse(ds);
}catch(ParseExceptione){
System.out.println("Unabletoparse"+ds);
}
<插入代码2>
d.setTime((1000*60*60*24)+d.getTime());
}
在<插入代码1>处创建一个DateFormat对象,在<插入代码2>处给Date对象d加上一天,下列选项正确的是:
A.
DateFormatdf=DateFormat.getDateFormat();
d.setTime((60*60*24)+d.getTime());
B.
DateFormatdf=DateFormat.getDateInstance();
d.setTime((1000*60*60*24)+d.getTime());
C.
DateFormatdf=DateFormat.getDateFormat();
d.setLocalTime((1000*60*60*24)+d.getLocalTime());
D.
DateFormatdf=DateFormat.getDateInstance();
d.setLocalTime((60*60*24)+d.getLocalTime());
13.
下列代码的输出结果是:
publicstaticvoidmain(String[]args){
BigDecimald1=newBigDecimal("3.0");
BigDecimald2=newBigDecimal("2.9");
BigDecimald3=d1.subtract(d2);
System.out.println(d3);
}
A.
0
B.
0.1
C.
0.10000000000000009
D.
0.10
14.
下列赋值语句中,正确的是()。
A.
byteb1=10,b2=20;
byteb=b1+b2;
B.
byteb1=10,b2=20;
byteb=~b1;
C.
byteb1=10,b2=20;
byteb=b1>>1;
D.
byteb1=10;
byteb=++b1;
15.
下列代码的输出结果是:
publicclassYikes{
publicstaticvoidgo(Longn){
System.out.println("Long");
}
publicstaticvoidgo(Shortn){
System.out.println("Short");
}
publicstaticvoidgo(intn){
System.out.println("int");
}
publicstaticvoidmain(String[]args){
shorty=6;
longz=7;
go(y);
go(z);
}
}
A.
Long
Long
B.
Short
Long
C.
int
Long
D.
int
int
16.
IO包中,唯一代表磁盘本身的对象类是()。
A.
FileInputStream
B.
File
C.
InputStream
D.
BufferedReader
17.
仔细分析下列代码,请指出错误的行()。
publicclassSomeThing{
privateStringstr;
publicintaddOne(finalintx){
return++x;
}
}
A.
publicclassSomeThing
B.
privateStringst