测试无答案.docx

上传人:b****3 文档编号:3746450 上传时间:2022-11-25 格式:DOCX 页数:26 大小:26.98KB
下载 相关 举报
测试无答案.docx_第1页
第1页 / 共26页
测试无答案.docx_第2页
第2页 / 共26页
测试无答案.docx_第3页
第3页 / 共26页
测试无答案.docx_第4页
第4页 / 共26页
测试无答案.docx_第5页
第5页 / 共26页
点击查看更多>>
下载资源
资源描述

测试无答案.docx

《测试无答案.docx》由会员分享,可在线阅读,更多相关《测试无答案.docx(26页珍藏版)》请在冰豆网上搜索。

测试无答案.docx

测试无答案

Questions

1.Whatwillhappenwhenyouattempttocompileandrunthefollowingcode?

publicclassStatic

{

static

{

intx=5;

}

staticintx,y;

publicstaticvoidmain(Stringargs[])

{

    x--;

    myMethod();

    System.out.println(x+y+++x);

}

publicstaticvoidmyMethod()

{

y=x+++++x;

}

}

Choices:

a.Compiletimeerror

b.prints:

1

c.prints:

2

d.prints:

3

e.prints:

7

f.prints:

8

2.Giventhefollowingcode,whatwillbetheoutput?

classValue

{

publicinti=15;

}

publicclassTest

{

publicstaticvoidmain(Stringargv[])

{

    Testt=newTest();

t.first();

  }

publicvoidfirst()

{

   inti=5;

    Valuev=newValue();

v.i=25;

second(v,i);

  System.out.println(v.i);

}

publicvoidsecond(Valuev,inti)

{

i=0;

    v.i=20;

Valueval=newValue();

    v= val;

  System.out.println(v.i+""+i);

        

}

}

Choices:

a.150

  20

b.150

  15

c.200

 20

d.015

 20

3.Whatwillhappenwhenyouattempttocompileandrunthefollowingcode?

classMyParent

{

intx,y;

MyParent(intx,inty)

{

this.x=x;

this.y=y;

}

publicintaddMe(intx,inty)

{

returnthis.x+x+y+this.y;

}

publicintaddMe(MyParentmyPar)

{

returnaddMe(myPar.x,myPar.y);

}

}

classMyChildextendsMyParent

{

intz;

MyChild(intx,inty,intz)

{

super(x,y);

this.z=z;

}

publicintaddMe(intx,inty,intz)

{

returnthis.x+x+this.y+y+this.z+z;

}

publicintaddMe(MyChildmyChi)

{

returnaddMe(myChi.x,myChi.y,myChi.z);

}

publicintaddMe(intx,inty)

{

returnthis.x+x+this.y+y;

}

}

publicclassMySomeOne

{

publicstaticvoidmain(Stringargs[])

{

MyChildmyChi=newMyChild(10,20,30);

MyParentmyPar=newMyParent(10,20);

intx=myChi.addMe(10,20,30);

inty=myChi.addMe(myChi);

intz=myPar.addMe(myPar);

System.out.println(x+y+z);

}

}

Choices:

a.300

b.240

c.120

d.180

e.Compilationerror

f.Noneoftheabove

4.Whatwillbetheresultofexecutingthefollowingcode?

1.  booleana=true;

2.  booleanb=false;

3.  booleanc=true;

4.  if(a==true)

5.  if(b==true)

6.  if(c==true)     System.out.println("Somethingsaretrueinthisworld");

7.  else          System.out.println("Nothingistrueinthisworld!

");

8.  elseif(a&&(b=c)) System.out.println("It'stooconfusingtotellwhatistrueandwhatisfalse");

9.  else          System.out.println("Heythiswon'tcompile");

Choices:

a. Thecodewon'tcompile

b."Somethingsaretrueinthisworld"willbeprinted

c."Heythiswon'tcompile"willbeprinted

d.Noneofthese

5. Whatwillhappenwhenyouattempttocompileandrunthefollowingcode?

interfaceMyInterface

{

}

publicclassMyInstanceTestimplementsMyInterface

{

staticStrings;

publicstaticvoidmain(Stringargs[])

{

MyInstanceTestt=newMyInstanceTest();

if(tinstanceofMyInterface)

{

System.out.println("Iamtrueinterface");

}

else

{

System.out.println("Iamfalseinterface");

}

if(sinstanceofString)

{

System.out.println("IamtrueString");

}

else

{

System.out.println("IamfalseString");

}

}

}

Choices:

a.Compiletimeerror

b.Runtimeerror

c.Prints:

"Iamtrueinterface"followedby"IamtrueString"

d.Prints:

"Iamfalseinterface"followedby"IamfalseString"

e.Prints:

"Iamtrueinterface"followedby"IamfalseString"

f.Prints:

"Iamfalseinterface"followedby"IamtrueString"

6.Whatresultsfromattemptingtocompileandrunthefollowingcode?

publicclassTernary

{

publicstaticvoidmain(Stringargs[])

{

inta=5;

System.out.println("Valueis-"+((a<5)?

9.9:

9));

}

}

Choices:

a. prints:

Valueis-9

b.prints:

Valueis-5

c.Compilationerror

d.Noneofthese

7.Inthefollowingpiecesofcode,AandDwillcompilewithoutanyerror.True/False?

A:

StringBuffersb1="abcd";

B:

Booleanb=newBoolean("abcd");

C:

byteb=255;

D:

intx=0x1234;

E:

floatfl=1.2;

Choices:

a.True

b.False

8.Consideringthefollowingcode,Whichvariablesmaybereferencedcorrectlyatline12?

1.publicclassOuter

2.{

3.publicinta=1;

4.privateintb=2;

5.publicvoidmethod(finalintc)

6.{

7.intd=3;

8.classInner

9.{

10.privatevoidiMethod(inte)

11.{

12.

13.}

14.}

15.}

16.}

Choices:

a.a

b.b

c.c

d.d

e.e

9.Whatwillbetheresultofexecutingthefollowingcode?

publicstaticvoidmain(Stringargs[])

{

  chardigit='a';

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

  {

   switch(digit)

   {

    case'x':

    {

    intj=0;

System.out.println(j);

    }

    default:

    {

    intj=100;

System.out.println(j);

    }

   }

 }

 

inti=j;

 System.out.println(i);

}

Choices:

a.100willbeprinted11times.

b.100willbeprinted10timesandthentherewillbearuntimeexception.

c.Thecodewillnotcompilebecausethevariableicannotbedeclaredtwicewithinthemain()method.

d.Thecodewillnotcompilebecausethevariablejcannotbedeclaredtwicewithintheswitchstatement.

e.Noneofthese.

10.Whatwillhappenwhenyouattempttocompileandrunthefollowingcode?

classMyThreadextendsThread

{

publicvoidrun()

{

System.out.println("MyThread:

run()");

}

publicvoidstart()

{

System.out.println("MyThread:

start()");

}

}

classMyRunnableimplementsRunnable

{

publicvoidrun()

{

System.out.println("MyRunnable:

run()");

}

publicvoidstart()

{

System.out.println("MyRunnable:

start()");

}

}

publicclassMyTest

{

publicstaticvoidmain(Stringargs[])

{

MyThreadmyThread = newMyThread();

MyRunnablemyRunnable=newMyRunnable();

Threadthread = newThread(myRunnable);

myThread.start();

thread.start();

}

}

Choices:

a.Prints:

MyThread:

start()followedbyMyRunnable:

run()

b.Prints:

MyThread:

run()followedbyMyRunnable:

start()

c.Prints:

MyThread:

start()followedbyMyRunnable:

start()

d.Prints:

MyThread:

run()followedbyMyRunnable:

run()

e.Compiletimeerror

f.Noneoftheabove

11.Giventhecodebelow,andmakingnootherchanges,whichaccessmodifiers

(public,protectedorprivate)canlegallybeplacedbeforemyMethod()online3?

Ifline3isleftasitis,whichkeywordscanlegallybeplacedbeforemyMethod

online8?

1.classHumptyDumpty

2.{

3.voidmyMethod(){}

4.}

5.

6.classHankyPankyextendsHumptyDumpty

7.{

8.voidmyMethod(){}

9.}

Choices:

a.privateornothing(i.e.leavingitasitis)online3.

Nothing(i.e.leavingitasitis)orprotectedorpublic

online8.

b.publicorprotectedonline3.privateornothing(i.e.leavingit

asitis)online8.

c.nothing(i.e.leavingitasitis)orprotectedorpublicon

line3.privateornothing(i.e.leavingitasitis)online8.

d.Noneoftheabove.

12. Whatwillbetheresultofexecutingthefollowingcode?

//Filename;SuperclassX.java

packagepackageX;

publicclassSuperclassX

{

protectedvoidsuperclassMethodX()

{

}

intsuperclassVarX;

}

//FilenameSubclassY.java

1.packagepackageX.packageY;

2.

3.publicclassSubclassYextendsSuperclassX

4.{

5.SuperclassXobjX=newSubclassY();

6.SubclassYobjY=newSubclassY();

7.voidsubclassMethodY()

8.{

9.objY.superclassMethodX();

10.inti;

11.i=objY.superclassVarX;

12.}

13.}

Choices:

a.Compilationerroratline5

b.Compilationerroratline9

c.Runtimeexceptionatline11

d.Noneofthese

13. Considertheclasshierarchyshownbelow:

   --------------------------------------------------------------------

classFourWheelerimplementsDrivingUtilities

classCarextendsFourWheeler

classTruckextendsFourWheeler

classBusextendsFourWheeler

classCraneextendsFourWheeler

----------------------------------------------------------------------

  

Considerthefollowingcodebelow:

1.DrivingUtilitiesdu;

2.FourWheelerfw;

3.TruckmyTruck=newTruck();

4.du=(DrivingUtilities)myTruck;

5.fw=newCrane();

6.fw=du;

Whichofthestatementsbelowaretrue?

Choices:

a.Line4willnotcompilebecauseaninterfacecannotrefertoanobject.

b.Thecodewillcompileandrun.

c.Thecodewillnotcompilewithoutanexplicitcastatline6,becausegoing

downthehierarchywithoutcastingisnotallowed.

d.Thecodeatline4willcompileevenwithouttheexplicitcast.

e.Thecodewillcompileifweputanexplicitcastatline6butwillthrowanexceptionatruntime.

14.Whatresultsfromthefollowingcode?

1.classMyClass

2.{

3.voidmyMethod(inti){System.out.println("intversion");}

4.voidmyMethod(Strings){System.out.println("Stringversion");}

5.publicstaticvoidmain(Stringargs[])

6.{

7.MyClassobj=newMyClass();

8.charch='c';

9.obj.myMethod(ch);

10.}

11.}

Choices:

a.Line4willnotcompileasvoidmethodscan'tbeoverridden.

b.Anexceptionatline9.

c.Line9willnotcompileasthereisnoversionofmyMethodwhichtakesacharasargument.

d.Thecodecompilesandproducesoutput:

intversion.

e.Thecodecompilesandproducesoutput:

Stringversion.

15.Whatistheresultwhenyoucompileandrunthefollowingcode?

publicclassThrowsDemo

   staticvoidthrowMethod()

       System.out.println("InsidethrowMethod."); 

       thrownewIllegalAccessException("demo"); 

   }

 

   publicstaticvoidmain(Stringargs[])

     try

        throwMethod(); 

     }

catch(IllegalAccessExceptione)

        System.out.println("Caught"+e); 

     } 

   } 

Choices:

a.Compilationerror

b.Runt

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

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1