java.docx

上传人:b****2 文档编号:2723196 上传时间:2023-05-04 格式:DOCX 页数:15 大小:18.45KB
下载 相关 举报
java.docx_第1页
第1页 / 共15页
java.docx_第2页
第2页 / 共15页
java.docx_第3页
第3页 / 共15页
java.docx_第4页
第4页 / 共15页
java.docx_第5页
第5页 / 共15页
java.docx_第6页
第6页 / 共15页
java.docx_第7页
第7页 / 共15页
java.docx_第8页
第8页 / 共15页
java.docx_第9页
第9页 / 共15页
java.docx_第10页
第10页 / 共15页
java.docx_第11页
第11页 / 共15页
java.docx_第12页
第12页 / 共15页
java.docx_第13页
第13页 / 共15页
java.docx_第14页
第14页 / 共15页
java.docx_第15页
第15页 / 共15页
亲,该文档总共15页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

java.docx

《java.docx》由会员分享,可在线阅读,更多相关《java.docx(15页珍藏版)》请在冰点文库上搜索。

java.docx

java

question1)

whatwillhappenwhenyouattempttocompileandrunthiscode?

abstractclassbase{

abstractpublicvoidmyfunc();

publicvoidanother(){

system.out.println("anothermethod");

}

}

publicclassabsextendsbase{

publicstaticvoidmain(stringargv[]){

absa=newabs();

a.amethod();

}

publicvoidmyfunc(){

system.out.println("myfunc");

}

publicvoidamethod(){

myfunc();

}

}

1)thecodewillcompileandrun,printingoutthewords"myfunc"

2)thecompilerwillcomplainthatthebaseclasshasnonabstractmethods

3)thecodewillcompilebutcomplainatruntimethatthebaseclasshasnonabstractmethods

4)thecompilerwillcomplainthatthemethodmyfuncinthebaseclasshasnobody,nobodyatalltoloooveit

question2)

whatwillhappenwhenyouattempttocompileandrunthiscode?

publicclassmymain{

publicstaticvoidmain(Stringargv){//改为:

main(String[]argv)

System.out.println("hellocruelworld");

}

}

1)thecompilerwillcomplainthatmainisareservedwordandcannotbeusedforaclass

2)thecodewillcompileandwhenrunwillprintout"hellocruelworld"

3)thecodewillcompilebutwillcomplainatruntimethatnoconstructorisdefined

4)thecodewillcompilebutwillcomplainatruntimethatmainisnotcorrectlydefined

question5)(不做)

whymightyoudefineamethodasnative?

1)togettoaccesshardwarethatjavadoesnotknowabout

2)todefineanewdatatypesuchasanunsignedinteger

3)towriteoptimisedcodeforperformanceinalanguagesuchasc/c++

4)toovercomethelimitationoftheprivatescopeofamethod

question6)

whatwillhappenwhenyouattempttocompileandrunthiscode?

classbase{

publicfinalvoidamethod(){

System.out.println("amethod");

}

}

publicclassfinextendsbase{

publicstaticvoidmain(Stringargv[]){

baseb=newbase();

b.amethod();

}

}

1)compiletimeerrorindicatingthataclasswithanyfinalmethodsmustbedeclaredfinalitself

2)compiletimeerrorindicatingthatyoucannotinherit(继承)fromaclasswithfinalmethods

3)runtimeerrorindicatingthatbaseisnotdefinedasfinal

4)successincompilationandoutputof"amethod"atruntime

question7)(不做)

whatwillhappenwhenyouattempttocompileandrunthiscode?

publicclassmod{

publicstaticvoidmain(Stringargv[]){

}

publicstaticnativevoidamethod();

}

1)erroratcompilation:

nativemethodcannotbestatic

2)erroratcompilationnativemethodmustreturnvalue

3)compilationbuterroratruntimeunlessyouhavemadecodecontainingnativeamethodavailable

4)compilationandexecutionwithouterror

question8)

whatwillhappenwhenyouattempttocompileandrunthiscode?

privateclassbase{}//类的修饰符只能是public,final,abstract

publicclassvis{

transientintival;

publicstaticvoidmain(Stringelephant[]){

}

}

1)compiletimeerror:

basecannotbeprivate

2)compiletimeerrorindicatingthatanintegercannotbetransient

3)compiletimeerrortransientnotadatatype

4)compiletimeerrormalformedmainmethod

question9)

whathappenswhenyouattempttocompileandrunthesetwofilesinthesamedirectory?

//filep1.java

packagemypackage;

classp1{

voidafancymethod(){

system.out.println("whatafancymethod");

}

}

//filep2.java

publicclassp2extendsp1{

publicstaticvoidmain(Stringargv[]){

p2p2=newp2();

p2.afancymethod();

}

}

1)bothcompileandp2outputs"whatafancymethod"whenrun

2)neitherwillcompile

3)bothcompilebutp2hasanerroratruntime

4)p1compilescleanlybutp2hasanerroratcompiletime

question10)

youwanttofindoutthevalueofthelastelementofanarray.youwritethefollowingcode.whatwillhappenwhenyoucompileandrunit.?

publicclassmyar{

publicstaticvoidmain(Stringargv[]){

int[]i=newint[5];

System.out.println(i[5]);//数组越界

}

}

1)anerroratcompiletime

2)anerroratruntime

3)thevalue0willbeoutput

4)thestring"null"willbeoutput

question18)

whatwillhappenwhenyouattempttocompileandrunthefollowingcode?

publicclassbgroundextendsthread{

publicstaticvoidmain(stringargv[]){

bgroundb=newbground();

b.run();//应该是重写run()方法,继承start()方法,

}

publicvoidstart(){

for(inti=0;i<10;i++){

system.out.println("valueofi="+i);

}

}

}

1)acompiletimeerrorindicatingthatnorunmethodisdefinedforthethreadclass

2)aruntimeerrorindicatingthatnorunmethodisdefinedforthethreadclass

3)cleancompileandatruntimethevalues0to9areprintedout

4)cleancompilebutnooutputatruntime

question25)

whatwillhappenwhenyouattempttocompileandrunthefollowingcode

publicclasshope{

publicstaticvoidmain(Stringargv[]){

hopeh=newhope();

}

protectedhope(){

for(inti=0;i<10;i++){

System.out.println(i);

}

}

}

1)compilationerror:

constructorscannotbedeclaredprotected

2)runtimeerror:

constructorscannotbedeclaredprotected

3)compilationandrunningwithoutput0to10

4)compilationandrunningwithoutput0to9

question26)

whatwillhappenwhenyouattempttocompileandrunthefollowingcode

publicclassmyswitch{

publicstaticvoidmain(Stringargv[]){

myswitchms=newmyswitch();

ms.amethod();

}

publicvoidamethod(){

intk=10;

switch(k){

case10:

system.out.println("ten");

case20:

system.out.println("twenty");

break;

default:

system.out.println("thisisthedefaultoutput");

break;

}

}

}

1)noneoftheseoptions//应该是tentwenty

2)compiletimeerrortargetofswitchmustbeanintegraltype

3)compileandrunwithoutput"thisisthedefaultoutput"

4)compileandrunwithoutputofthesingleline"ten"

question28)

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

2)compilationsucceedsandatruntimeanoutputof0andtrue

3)compiletimeerrorbisnotinitialised

4)compiletimeerrorzmustbeassignedacharvalue

question29)

whatwillhappenwhenyouattempttocompileandrunthefollowingcodewiththecommandline"hellothere"

publicclassarg{

string[]myarg;

publicstaticvoidmain(stringargv[]){

myarg=argv;//静态方法只能使用静态变量,myarg不是静态变量

}

publicvoidamethod(){

System.out.println(argv[1]);//argv是局部变量,在这个函数里不能使用

}

}

1)compiletimeerror

2)compilationandoutputof"hello"

3)compilationandoutputof"there"

4)noneoftheabove

question30)

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"

3)outputof"notequal"

4)compiletimeerrorbyattemptingtocomparestringsusing==

question31)

whatwillhappenwhenyouattempttocompileandrunthefollowingcode

importjava.io.*;

classbase{

publicvoidamethod()throwsfilenotfoundexception{}

}

publicclassexcepdemoextendsbase{

publicstaticvoidmain(stringargv[]){

excepdemoe=newexcepdemo();

}

publicvoidamethod(){}//重写方法时,子类的方法抛出的异常只能比父类的少,不能比父类多

protectedexcepdemo(){

try{

datainputstreamdin=newdatainputstream(system.in);

system.out.println("pausing");

din.readbyte();

system.out.println("continuing");

this.amethod();

}catch(ioexceptionioe){}

}

}

1)compiletimeerrorcausedbyprotectedconstructor

2)compiletimeerrorcausedbyamethodnotdeclaringexception

3)runtimeerrorcausedbyamethodnotdeclaringexception

4)compileandrunwithoutputof"pausing"and"continuing"afterakeyishit

question32)

whatwillhappenwhenyouattempttocompileandrunthisprogram

publicclassouter{

publicstringname="outer";

publicstaticvoidmain(stringargv[]){

inneri=newinner();

i.showname();

}//endofmain

privateclassinner{

stringname=newstring("inner");

voidshowname(){

system.out.println(name);

}

}//endofinnerclass

}

1)compileandrunwithoutputof"outer"

2)compileandrunwithoutputof"inner"

3)compiletimeerrorbecauseinnerisdeclaredasprivate

4)compiletimeerrorbecauseofthelinecreatingtheinstanceofinner

question33)(不做)

whatwillhappenwhenyouattempttocompileandrunthiscode

//demonstrationofeventhandling

importjava.awt.*;

importjava.awt.event.*;

publicclassmywcextendsframeimplementswindowlistener{

publicstaticvoidmain(stringargv[]){

mywcmwc=newmywc();

}

publicvoidwindowclosing(windoweventwe){

system.exit(0);

}//endofwindowclosing

publicvoidmywc(){

setsize(300,300);

setvisible(true);

}

}//endofclass

1)erroratcompiletime

2)visibleframecreatedthatthatcanbeclosed

3)compilationbutnooutputatruntime

4)erroratcompiletimebecauseofcommentbeforeimportstatements

question34)

whichoptionmostfullydescribeswillhappenwhenyouattempttocompileandrunthefollowingcode

publicclassmyar{

publicstaticvoidmain(stringargv[]){

myarm=newmyar();

m.amethod();

}

publicvoidamethod(){

staticinti;//局部变量不能定义为static,编译出错

system.out.println(i);

}

}

1)compilationandoutputofthevalue0

2)compiletimeerrorbecauseihasnotbeeninitialized

3)compilationandoutputofnull

4)compiletime

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2