0901模拟考试.docx
- 文档编号:25873129
- 上传时间:2023-06-16
- 格式:DOCX
- 页数:25
- 大小:21.80KB
0901模拟考试.docx
《0901模拟考试.docx》由会员分享,可在线阅读,更多相关《0901模拟考试.docx(25页珍藏版)》请在冰豆网上搜索。
0901模拟考试
Question1)
Whatwillhappenwhenyouattempttocompileandrunthiscode?
当试图编译并运行下面程序时会出现什么结果?
abstractclassBase{
abstractpublicvoidmyfunc();
publicvoidanother(){
System.out.println("Anothermethod");
}
}
publicclassAbsextendsBase{
publicstaticvoidmain(Stringargv[]){
Basea=newAbs();
a.another();
}
publicvoidmyfunc(){
System.out.println("MyFunc");
}
publicvoidanother(){
myfunc();
}
}
1)Thecodewillcompileandrun,printingoutthewords"MyFunc"
代码编译、运行并打印出“MyFunc”
2)ThecompilerwillcomplainthattheBaseclasshasnonabstractmethods
编译器会报怨Baseclass有非抽象方法
3)ThecodewillcompilebutcomplainatruntimethattheBaseclasshasnonabstractmethods
代码可以编译通过,但运行时会报Baseclass有非抽象方法
4)Thecompilerwillcomplainthatthemethodmyfuncinthebaseclasshasnobody
编译器会报Baseclass没有方法体
AnswertoQuestion1
--------------------------------------------------------------------------------
Question2)
Whatwillhappenwhenyouattempttocompileandrunthiscode?
当试图编译并运行下面程序时会出现什么结果?
publicclassMyMain{
publicstaticvoidmain(Stringargv){
System.out.println("Hellocruelworld");
}
}
1)Thecompilerwillcomplainthatmainisareservedwordandcannotbeusedforaclass
编译器报怨main属于保留字而不能在一个class中使用
2)Thecodewillcompileandwhenrunwillprintout"Hellocruelworld"
代码将编译、运行并输出“Hellocruelworld”
3)Thecodewillcompilebutwillcomplainatruntimethatnoconstructorisdefined
代码编译通过但运行时报没有定义构造方法
4)Thecodewillcompilebutwillcomplainatruntimethatmainisnotcorrectlydefined
代码编译通过但运行时报main方法没有正确定义
AnswertoQuestion2
--------------------------------------------------------------------------------
Question3)
WhichofthefollowingareJavamodifiers?
下面哪些是java修饰符?
1)public
2)private
3)friendly
4)transient
5)vagrant
AnswertoQuestion3
--------------------------------------------------------------------------------
Question4)
Whatwillhappenwhenyoucompileandrunit.?
当编译并运行下面程序时会出现什么结果?
publicclassMyAr{
publicstaticvoidmain(Stringargv[]){
int[]i=newint[5];
System.out.println(i[5]);
}
}
1)Anerroratcompiletime
编译出错
2)Anerroratruntime
运行出错
3)Thevalue0willbeoutput
输出0
4)Thestring"null"willbeoutput
输出“null”
AnswertoQuestion4
--------------------------------------------------------------------------------
Question5)
Whatbestdescribestheappearanceofanapplicationwiththefollowingcode?
下面哪个能最恰当的描述这个程序的运行效果?
importjava.awt.*;
publicclassFlowApextendsFrame{
publicstaticvoidmain(Stringargv[]){
FlowApfa=newFlowAp();
fa.setSize(400,300);
fa.setVisible(true);
}
FlowAp(){
add(newButton("One"));
add(newButton("Two"));
add(newButton("Three"));
add(newButton("Four"));
}//Endofconstructor
}//EndofApplication
1)AFramewithbuttonsmarkedOnetoFourplacedoneachedge.
窗体的每个边上依次放置按钮One到按钮Four
2)AFramewithbuttonsmarkedOnetofourrunningfromthetoptobottom
按钮从上到下依次摆放在窗体上上
3)AFramewithonelargebuttonmarkedFourintheCentre
按钮Four作为一个大的按钮放在窗体的中间
4)AnErroratruntimeindicatingyouhavenotsetaLayoutManager
运行出错,因为没有设置LayoutManager布局管理器
AnswertoQuestion5
--------------------------------------------------------------------------------
Question6)
Howdoyouchangethecurrentlayoutmanagerforacontainer
如何改变容器的布局管理器?
1)UsethesetLayoutmethod
采用setLayout方法
2)Oncecreatedyoucannotchangethecurrentlayoutmanagerofacontainer
一旦产生,你无法改变容器当前的布局管理器
3)UsethesetLayoutManagermethod
采用setLayoutManager方法
4)UsetheupdateLayoutmethod
采用updateLayout方法
AnswertoQuestion6)
--------------------------------------------------------------------------------
Question7)
Whatmostcloselymatchestheappearancewhenthiscoderuns?
当运行下面代码时,哪个最接近程序的结果?
importjava.awt.*;
publicclassCompLayextendsFrame{
publicstaticvoidmain(Stringargv[]){
CompLaycl=newCompLay();
}
CompLay(){
Panelp=newPanel();
p.setBackground(Color.pink);
p.add(newButton("One"));
p.add(newButton("Two"));
p.add(newButton("Three"));
add("South",p);
setLayout(newFlowLayout());
setSize(300,300);
setVisible(true);
}
}
1)ThebuttonswillrunfromlefttorightalongthebottomoftheFrame
按钮沿着窗体的底部从左到右摆放
2)Thebuttonswillrunfromlefttorightalongthetopoftheframe
按钮沿着窗体的顶部从左到右摆放
3)Thebuttonswillnotbedisplayed
所有按钮将不显示
4)Onlybuttonthreewillshowoccupyingalloftheframe
只有按钮3显示并占据整个窗体
AnswertoQuestion7)
--------------------------------------------------------------------------------
Question8)
Whatwillhappenwhenyouattempttocompileandrunthefollowingcode?
当编译并运行下面程序时会发生什么结果?
publicclassBgroundextendsThread{
publicstaticvoidmain(Stringargv[]){
Bgroundb=newBground();
b.run();
}
publicvoidstart(){
for(inti=0;i<10;i++){
System.out.println("Valueofi="+i);
}
}
}
1)AcompiletimeerrorindicatingthatnorunmethodisdefinedfortheThreadclass
编译错误,指明run方法没有定义
2)AruntimeerrorindicatingthatnorunmethodisdefinedfortheThreadclass
运行错误,指明run方法没有定义
3)Cleancompileandatruntimethevalues0to9areprintedout
编译通过并输出0到9
4)Cleancompilebutnooutputatruntime
编译通过但无输出
AnswertoQuestion8)
-------------------------------------------------------------------------------
Question9)
Foraclassdefinedinsideamethod,whatrulegovernsaccesstothevariablesoftheenclosingmethod?
对于定义在方法内部的类来说,它可以访问该方法的哪些变量?
1)Theclasscanaccessanyvariable
可以访问任何变量
2)Theclasscanonlyaccessstaticvariables
只能访问静态变量
3)Theclasscanonlyaccesstransientvariables
只能访问transient变量
4)Theclasscanonlyaccessfinalvariables
只能访问final常量
AnswertoQuestion9)
--------------------------------------------------------------------------------
Question10)
Whatwillhappenwhenyouattempttocompileandrunthefollowingcode
当编译并运行下面程序时会发生什么结果?
publicclassHope{
publicstaticvoidmain(Stringargv[]){
Hopeh=newHope();
}
protectedHope(){
for(inti=0;i<10;i++){
System.out.println(i);
}
}
}
1)Compilationerror:
Constructorscannotbedeclaredprotected
编译错误,构造方法不能被声明为protected
2)Runtimeerror:
Constructorscannotbedeclaredprotected
运行错误,构造方法不能被声明为protected
3)Compilationandrunningwithoutput0to10
编译并运行输出0到10
4)Compilationandrunningwithoutput0to9
编译并运行输出0到9
AnswertoQuestion10)
--------------------------------------------------------------------------------
Question11)
Whatwillhappenwhenyouattempttocompileandrunthefollowingcode
当编译并运行下面程序时会发生什么结果?
publicclassMySwitch{
publicstaticvoidmain(Stringargv[]){
MySwitchms=newMySwitch();
ms.amethod();
}
publicvoidamethod(){
intk=10;
switch(k){
default:
System.out.println("Thisisthedefaultoutput");
break;
case10:
System.out.println("ten");
case20:
System.out.println("twenty");
break;
}
}
}
1)Noneoftheseoptions
无解
2)Compiletimeerrortargetofswitchmustbeanintegraltype
编译错误,switch要求是integral类型
3)Compileandrunwithoutput"Thisisthedefaultoutput"
编译并运行输出“Thisisthedefaultoutput”
4)Compileandrunwithoutputofthesingleline"ten"
编译并运行输出“ten”
AnswertoQuestion11)
--------------------------------------------------------------------------------
Question12)
WhichofthefollowingisthecorrectsyntaxforsuggestingthattheJVMperformsgarbagecollection
JVM执行垃圾回收的正确语法是什么?
1)System.free();
2)System.setGarbageCollection();
3)System.out.gc();
4)System.gc();
AnswertoQuestion12)
--------------------------------------------------------------------------------
Question13)
Whatwillhappenwhenyouattempttocompileandrunthefollowingcode
当编译并运行下面程序时会发生什么结果?
publicclassAs{
inti=10;
intj;
charz=1;
booleanb;
publicstaticvoidmain(Stringargv[]){
Asa=newAs();
a.amethod();
}
publicvoidamethod(){
System.out.println(j);
System.out.println(b);
}
}
1)Compilationsucceedsandatruntimeanoutputof0andfalse
编译并运行输出0和false
2)Compilationsucceedsandatruntimeanoutputof0andtrue
编译并运行输出0和true
3)Compiletimeerrorbisnotinitialized
编译错误报变量b没有初始化
4)Compiletimeerrorzmustbeassignedacharvalue
编译错误,变量z必须赋予一个字符
AnswertoQuestion13)
--------------------------------------------------------------------------------
Question14)
Whatwillhappenwhenyouattempttocompileandrunthefollowingcode
当编译并运行下面程序时会发生什么结果?
publicclassStrEq{
publicstaticvoidmain(Stringargv[]){
StrEqs=newStrEq();
}
privateStrEq(){
Strings="Marcus";
Strings2=newString("Marcus");
if(s==s2){
System.out.println("wehaveamatch");
}else{
System.out.println("Notequal");
}
}
}
1)Compiletimeerrorcausedbyprivateconstructor
编译错误报构造方法私有化
2)Outputof"wehaveamatch"
输出“wehaveamatch”
3)Outputof"Notequal"
输出“Notequal”
4)Compiletimeerrorbyattemptingtocomparestringsusing==
编译错误,由于采用了==作比较
AnswertoQuestion14)
--------------------------------------------------------------------------------
Question15)
Whatwillhappenwhenyouattempttocompileandrunthisprogram
当编译并运行下面程序时会发生什么结果?
publicclassOuter{
publicStringname="Outer";
publicstaticvoidmain(Stringargv[]){
Inneri=newInner();
i.showName();
}//Endofmain
privateclassInner{
Stringname=newString("Inner");
voidshowName(){
System.out.println(name);
}
}//EndofInnerclass
}
1)Compileandrunwithoutputof"Outer"
编译并运行输出“Outer”
2)Compileandrunwithoutputof"Inner"
编译并运行输出“Inner”
3)CompiletimeerrorbecauseInnerisdeclaredasprivate
编译错误,Inner被声明为private
4)Compiletimeerrorbecauseofthelinecreatingthe
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 0901 模拟考试