JAVA试题英文版答案.docx
- 文档编号:6577344
- 上传时间:2023-01-08
- 格式:DOCX
- 页数:9
- 大小:17.76KB
JAVA试题英文版答案.docx
《JAVA试题英文版答案.docx》由会员分享,可在线阅读,更多相关《JAVA试题英文版答案.docx(9页珍藏版)》请在冰豆网上搜索。
JAVA试题英文版答案
一.Whichtwodemonstratean“isa”relationship?
(ChooseTwo)
A.publicinterfacePerson{}//语法错了
publicclassEmployeeextendsPerson{}
B.publicinterfaceShape{}//语法错了
publicclassEmployeeextendsShape{}
C.publicinterfaceColor{}//语法错了
publicclassEmployeeextendsColor{}
D.publicclassSpecies{}
publicclassAnimal{privateSpeciesspecies;}
E.interfaceComponent{}
ClassContainerimplementsComponent(
PrivateComponent[]children;
二.whichstatementistrue?
A.Ananonymousinnerclassmaybedeclaredasfinal
B.Ananonymousinnerclasscanbedeclaredasprivate
C.Ananonymousinnerclasscanimplementmutipleinterfaces
D.Ananonymousinnerclasscanaccessfinalvariablesinanyenclosingscope(不能)
E.Constructionofaninstanceofastaticinnerclassrequiresaninstanceoftheencloingouterclass
构造一个静态的内部类对象需要构造包含它的外部类的对象
三.Given:
1.packagefoo;
2.
3.publicclassOuter(
4. publicstaticclassInner(
5. )
6.)
Whichstatementistrue?
A.AninstanceoftheInnerclasscanbeconstructedwith“newOuter.Inner()”
B.Aninstanceoftheinnerclasscannotbeconstructedoutsideofpackagefoo
他们都是public的,只要在外部import就行
C.Aninstanceoftheinnerclasscanonlybeconstructedfromwithintheouterclass
D.Fromwithinthepackagebar,aninstanceoftheinnerclasscanbeconstructedwith“newinner()”
四.Exhibit(展览、陈列):
1publicclassenclosinggone{
2publicclassinsideone{}
3}
4publicclassinertest{
5publicstaticvoidmain(String[]args){
6enclosingoneeo=newenclosingone();
7//insertcodehere
8}
}
Whichstatementatline7constructsaninstanceoftheinnerclass?
A.InsideOneei=eo.newInsideOne();写程序试出来
B.Eo.InsideOneei=eo.newInsideOne();
CInsideOneei=EnclosingOne.newInsideOne();
D.EnclosingOneInsideOneei=eo.newInsideOne();
五.
1) interfaceFoo{
2) intk=0;
3) }
4)publicclassTestimplementsFoo{
5) publicstaticvoidmain(Stringargs[]){
6) inti;
7) Testtest=newTest();
8) i=test.k;
9) i=Test.k;
10) i=Foo.k;
11) }
12)}
Whatistheresult?
A.Compilationsucceeds.
B.Anerroratline2causescompilationtofail.
C.Anerroratline9causescompilationtofail.
D.Anerroratline10causescompilationtofail.
E.Anerroratline11causescompilationtofail.
六.
//pointX
publicclassFoo{
publicstaticvoidmain(String[]args){
PrintWriterout=newPrintWriter(newjava.io.OutputStreamWriter(System.out),true);
out.println("Hello");
}
}
whichstatementatpointXonline1allowsthiscodetocompileandrun?
在pointX这个位置要填入什么代码才能使程序运行
A.importjava.io.PrintWriter B.includejava.io.PrintWriter
C.importjava.io.OutputStreamWriter D.includejava.io.OutputStreamWriter
E.Nostatementisneeded
本来两个都要import,但是后者OutputStreamWriter指定了包结构java.io.OutputStreamWriter
七.whatisreservedwordsinjava?
保留字而非关键字
A.run
B.default
C.implement
D.import
八.whichthreearevaliddeclaractionofafloat?
(float作为整数是可以的,其余几个都是double)
A.floatfoo=-1;
B.floatfoo=1.0;
C.floatfoo=42e1;
D.floatfoo=2.02f;
E.floatfoo=3.03d;
F.floatfoo=0x0123;
九. Given:
8. intindex=1;
9. boolean[]test=newboolean[3];(数组作为对象缺省初始化为false)
10.booleanfoo=test[index];
Whatistheresult?
A.foohasthevalueof0
B.foohasthevalueofnull
C.foohasthevalueoftrue
D.foohasthevalueoffalse
E.anexceptionisthrown
F.thecodewillnotcompile
十.Given:
1.publicclasstest(
2.publicstaticvoidmain(String[]args){
3.Stringfoo=args[1];
4.Stringfoo=args[2];
5.Stringfoo=args[3];
6.}
7.}
Andthecommandlineinvocation:
JavaTest
Whatistheresult?
A.bazhasthevalueof“”
B.bazhasthevalueofnull
C.bazhasthevalueof“red”
D.bazhasthevalueof“blue”
E.baxhasthevalueof“green”
F.thecodedoesnotcompile
G.theprogramthrowsanexception
(此题题目出错了,重复定义了变量foo,如果没有重复的话,应选G,因为只传递了0-2三个数组元素,而题目中需要访问args[3],所以会抛出数组越界异常)
十一.
intindex=1;
intfoo[]=newint[3];
intbar=foo[index];//bar=0
intbaz=bar+index;//baz=1
whatistheresult?
A.bazhasavalueof0
B.bazhasvalueof1
C.bazhasvalueof2
D.anexceptionisthrown
E.thecodewillnotcompile
十二.
1)publicclassFoo{
2)publicstaticvoidmain(Stringargs[]){
3)Strings;
4)System.out.println("s="+s);
5) }
6)}
whatistheresult?
A.Thecodecompilesand“s=”isprinted.
B.Thecodecompilesand“s=null”isprinted.
C.Thecodedoesnotcompilebecausestringsisnotinitialized.
D.Thecodedoesnotcompilebecausestringscannotbereferenced.
E.Thecodecompiles,butaNullPointerExceptionisthrownwhentoStringiscalled.
十三.Whichwilldeclareamethodthatforcesasubclasstoimplementit?
(谁声明了一个方法,子类必须实现它)
A.publicdoublemethoda();
B.staticvoidmethoda(doubled1){}
C.publicnativedoublemethoda();
D.abstractpublicvoidmethoda();
E.protectedvoidmethoda(doubled1){}
十四.
Youwantsubclassesinanypackagetohaveaccesstomembersofasuperclass.Whichisthemostrestrictiveaccessmodifierthatwillaccomplishthisobjective?
(你希望子类在任何包里都能访问父类,为完成这个目的,下列哪个是最严格的访问权限)
A.Public
B.Private
C.Protected
D.Transient
E.Noaccessmodifierisqualified
十五.Given:
1.abstractclassabstrctIt{
2.abstractfloatgetFloat();
3.)
4.publicclassAbstractTestextendsAbstractIt{
5.privatefloatf1=1.0f;
6.privatefloatgetFloat(){returnf1;}
7.}
Whatistheresult?
A.Compilationissuccessful.
B.Anerroronline6causesaruntimefailure.(抛出实时异常)
C.Anerroratline6causescompilationtofail.
D.Anerroratline2causescompilationtofail.
(子类覆盖父类方法的时候,不能比父类方法具有更严格的访问权限)
十六.Clicktheexhibitbutton:
1. publicclasstest{
2. publicintaMethod(){
3. staticinti=0;
4. i++;
5. returnI;
6. }
7. publicstaticvoidmain(Stringargs[]){
8. testtest=newtest();
9. test.aMethod();
10.intj=test.aMethod();
11.System.out.printIn(j);
12.}
13.}
(局部变量不能声明为静态)
Whatistheresult?
A.Compilationwillfail.
B.Compilationwillsucceedandtheprogramwillprint“0”.
C.Compilationwillsucceedandtheprogramwillprint“1”.
D.Compilationwillsucceedandtheprogramwillprint“2”.
十七.
1) classSuper{
2) publicfloatgetNum(){return3.0f;}
3) }
4)
5) publicclassSubextendsSuper{
6)
7) }
whichmethod,placedatline6,willcauseacompilererror?
A.publicfloatgetNum(){return4.0f;}
B.publicvoidgetNum(){}返回值类型不同不足以构成方法的重载
C.publicvoidgetNum(doubled){}
D.publicdoublegetNum(floatd){return4.0d;}
十八.Whichdeclarationpreventscreatingasubclassofanouterclass?
A.staticclassFooBar{}
B.pivateclassFoobar{}
C.abstractclassFooBar{}
D.finalpublicclassFooBar{}
E.finalabstractclassFooBar{}抽象类不能声明为final
十九.byte[]array1,array2[]
bytearray3[][]
byte[][]array4
ifeachhasbeeninitialized,whichstatementwillcauseacompileerror?
A.array2=array1;
B.array2=array3;
C.array2=array4;
D.bothAandB
E.bothAandC
F.bothBandC(一维数组和二维数组的区别)
二十.
classSuper{
publicinti=0;
publicSuper(Stringtext){
i=1;
}
}
publicclassSubextendsSuper{
publicSub(Stringtext){
i=2;
}
publicstaticvoidmain(Stringargs[]){
Subsub=newSub("Hello");
System.out.println(sub.i);
}
}
whatistheresult?
A.compilewillfail
B.compilesuccessandprint"0"
C.compilesuccessandprint"1"
D.compilesuccessandprint"2"
子类总要去调用父类的构造函数,有两种调用方式,自动调用(无参构造函数),主动调用带参构造函数。
(注:
文档可能无法思考全面,请浏览后下载,供参考。
)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- JAVA 试题 英文 答案