java认证 习题 第06章 有答案版 OK该试题还有第0405章文档格式.docx
- 文档编号:7381922
- 上传时间:2023-05-08
- 格式:DOCX
- 页数:26
- 大小:20.82KB
java认证 习题 第06章 有答案版 OK该试题还有第0405章文档格式.docx
《java认证 习题 第06章 有答案版 OK该试题还有第0405章文档格式.docx》由会员分享,可在线阅读,更多相关《java认证 习题 第06章 有答案版 OK该试题还有第0405章文档格式.docx(26页珍藏版)》请在冰点文库上搜索。
A.Allthreeclasseshavealength()method.
B.ObjectsoftypeStringBufferarethread-safe.
C.Allthreeclasseshaveoverloadedappend()methods.
D.The"
+"
isanoverloadedoperatorforallthreeclasses.
E.AccordingtotheAPI,StringBufferwillbefasterthanStringBuilderundermost
implementations.
F.Thevalueofaninstanceofanyofthesethreetypescanbemodifiedthroughvarious
methodsintheAPI.
3(13)Given:
classPolish{
intx=4;
StringBuffersb=newStringBuffer("
..fedcba"
);
sb.delete(3,6);
sb.insert(3,"
az"
if(sb.length()>
6)x=sb.indexOf("
b"
sb.delete((x-3),(x-2));
System.out.println(sb);
Whatistheresult?
A..faza
B..fzba
C...azba
D..fazba
E...fezba
4(22)
whatStringinstancemethodwouldreturntruewheninvokedlikethis
a.method(b);
wherea="
GROUNDhog"
andb="
groundHOG"
selectallanswers
A.equals()
B.toLowercase()
C.toUppercase()
D.equalsIgnoreCase()
E.Noneoftheabove
5(25)
Attheendofthesetwolinesofcode:
Strings="
hypertext"
Stringt=s.subString(2,5);
Whatdoestheobjectreferencetcontain?
A."
yper"
B."
ype"
C."
pert"
D."
per"
E."
perte"
6(26)
Whichofhefollowingstatementswouldreturnfalse?
ifgiventhefollowingstatements
Strings=newString("
Newyear"
Strings1=newString("
newYear"
A.s==s1
B.s.equals(s1)
C.s=s1;
D.noneoftheabove
7(28)
Whichwillcompileandrunwithoutexception,generatetheoutput4247
A.classExample{
publicstaticvoidmain(String[]args){
Strings="
123456789"
s=(s-"
123"
).replace(1,3,"
24"
)-"
89"
System.out.println(s);
}
}
B.classExample{
StringBuffers=newStringBuffer("
s.delete(0,3).replace(1,3,"
).delete(4,6)
C.classExample{
s.substring(3,6).delete(1,3).insert(1,"
D.classExample{
StringBuilders=newStringBuilder("
s.substring(3,6).delete(1,2).insert(1,"
8(29)
classExample{
ABCD"
s.concat("
E"
s.replace('
C'
'
F'
whatwillbeprintedout?
A.CompilationErrorssaystheStringisimmutable
B.ABFDE
C.ABCDE
D.ABCD
9(33)
Stringstr="
Welcome"
str.concat("
Tojava"
System.out.println(str);
A.theStringisimmutable,CompilationErrorsatline3
B.theStringisimmutable,RunExceptionatline3
C.Prints"
D.prints"
WelcomeTojava"
10.(39)
Strings1=newString("
amit"
Strings2=s1.replace('
m'
i'
s1.concat("
Poddar"
System.out.println(s1);
System.out.println((s1+s2).charAt(5));
A.CompilationError
B.amitPoddaro
C.amitPoddari
D.amiti
二、I/O、串行化
1
(2)Given:
importjava.io.*;
classPlayer{
Player(){System.out.print("
p"
}
classCardPlayerextendsPlayerimplementsSerializable{
CardPlayer(){System.out.print("
c"
CardPlayerc1=newCardPlayer();
try{
FileOutputStreamfos=newFileOutputStream("
play.txt"
ObjectOutputStreamos=newObjectOutputStream(fos);
os.writeObject(c1);
os.close();
FileInputStreamfis=newFileInputStream("
ObjectInputStreamis=newObjectInputStream(fis);
CardPlayerc2=(CardPlayer)is.readObject();
is.close();
}catch(Exceptionx){}
A.pc
B.pcc
C.pcp
D.pcpc
E.Compilationfails.
F.Anexceptionisthrownatruntime.
2(3)
Given:
bwisareferencetoavalidBufferedWriter
Andthesnippet:
15.BufferedWriterb1=newBufferedWriter(newFile("
f"
));
16.BufferedWriterb2=newBufferedWriter(newFileWriter("
f1"
17.BufferedWriterb3=newBufferedWriter(newPrintWriter("
f2"
18.BufferedWriterb4=newBufferedWriter(newBufferedWriter(bw));
A.Compilationsucceeds.
B.Compilationfailsdueonlytoanerroronline15.
C.Compilationfailsdueonlytoanerroronline16.
D.Compilationfailsdueonlytoanerroronline17.
E.Compilationfailsdueonlytoanerroronline18.
F.Compilationfailsduetoerrorsonmultiplelines.
3(6)
classKeyboard{}
publicclassComputerimplementsSerializable{
privateKeyboardk=newKeyboard();
Computerc=newComputer();
c.storeIt(c);
voidstoreIt(Computerc){
ObjectOutputStreamos=newObjectOutputStream(
newFileOutputStream("
myFile"
os.writeObject(c);
System.out.println("
done"
}catch(Exceptionx){System.out.println("
exc"
A.exc
B.done
C.Compilationfails.
D.Exactlyoneobjectisserialized.
E.Exactlytwoobjectsareserialized.
4(7)
Giventhefewestfragmentspossible(andfillingthefewestslotspossible),completethecode
belowsothattheclassbuildsadirectorynamed"
dir3"
andcreatesafilenamed"
file3"
inside
"
.Noteyoucanuseeachfragmenteitherzerooronetimes.
Code:
importjava.io.______________
classMaker{
_________________________________
Fragments:
File;
FileDescriptor;
FileWriter;
Directory;
try{.createNewDir();
FiledirFile
{}(Exceptionx)("
file
file.createNewFile();
=newFile=newFile
dir(dir,"
(dir,file);
.createFile();
}catch("
"
.mkdir();
Filefile
Answer:
importjava.io.File;
Filedir=newFile("
dir.mkdir();
Filefile=newFile(dir,"
file.createNewFile();
}catch(Exceptionx){}
5(12)
classDirectories{
staticString[]dirs={"
dir1"
dir2"
};
publicstaticvoidmain(String[]args){
for(Stringd:
dirs){
//insertcode1here
Filefile=newFile(path,args[0]);
//insertcode2here
andthattheinvocation
javaDirectoriesfile2.txt
isissuedfromadirectorythathastwosubdirectories,"
and"
andthat"
hasa
file"
file1.txt"
hasafile"
file2.txt"
andtheoutputis"
falsetrue"
which
set(s)ofcodefragmentsmustbeinserted?
A.Stringpath=d;
System.out.print(file.exists()+"
"
B.Stringpath=d;
System.out.print(file.isFile()+"
C.Stringpath=File.separator+d;
D.Stringpath=File.separator+d;
6(15)
publicclassTestSer{
SpecialSerials=newSpecialSerial();
os.writeObject(s);
os.close();
System.out.print(++s.z+"
ObjectInputStreamis=newObjectInputStream(
newFileInputStream("
SpecialSerials2=(SpecialSerial)is.readObject();
System.out.println(s2.y+"
+s2.z);
classSpecialSerialimplementsSerializable{
transientinty=7;
staticintz=9;
Whicharetrue?
A.Compilationfails.
B.Theoutputis1009
C.Theoutputis10010
D.Theoutputis1079
E.Theoutputis10710
F.InordertoalterthestandarddeserializationprocessyouwouldoverridethereadObject()
methodinSpecialSerial.
G.Inordertoalterthestandarddeserializationprocessyouwouldoverridethe
defaultReadObject()methodinSpecialSerial.
7(3)Whatisresultwhenyoucompileandrunthefollowingcode?
publicclassExample
{publicstaticvoidmain(String[]args){
Filef=newFile("
hello.test"
try{
FileOutputStreamout=newFileOutputStream(f);
catch(FileNotFoundExceptione){}
A.Createanewfilenamed"
ifitdoesnotyetexit.Italsoopensthefilesoyoucanwritetoitandreadfromit
B.Createanewfilenamed"
ifitdoesnotyetexit.Thefileisnotopened
C.openafilenamed"
sothatyoucanwritetoitandreadfromit,butdoesnotcreatethefileifitdoesnotyetexit
D.openafilenamed"
sothatyoucanwritetoitbutcannotreadfromit
8(4)Whatisresultwhenyoucompileandrunthefollowingcode?
c:
\\large.txt"
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java认证 习题 第06章 有答案版 OK 该试题还有第0405章 java 认证 06 答案 试题 还有 0405