System.out.println(ar[i]);
}
}
Anyclassderivedfromanabstractclassmusteitherdefinealloftheabstractmethodsorbedeclaredabstractitself.
1)asequenceof50'swillbeprinted
2)Error:
arisusedbeforeitisinitialized
3)ErrorMinemustbedeclaredabstract
4)IndexOutOfBoundesError
--------------------------------------------------------------------------------
Question12)
Whatwillbeprintedoutifyouattempttocompileandrunthefollowingcode?
inti=1;
switch(i){
case0:
System.out.println("zero");
break;
case1:
System.out.println("one");
case2:
System.out.println("two");
default:
System.out.println("default");
}
1)one
2)one,default
3)one,two,default
4)default
--------------------------------------------------------------------------------
Question13)
Whatwillbeprintedoutifyouattempttocompileandrunthefollowingcode?
inti=9;
switch(i){
default:
System.out.println("default");
case0:
System.out.println("zero");
break;
case1:
System.out.println("one");
case2:
System.out.println("two");
}
1)default
2)default,zero
3)errordefaultclausenotdefined
4)nooutputdisplayed
--------------------------------------------------------------------------------
Question14)
Whichofthefollowinglinesofcodewillcompilewithouterror
1)inti=0;
if(i){
System.out.println("Hello");
}
2)booleanb=true;
booleanb2=true;
if(b==b2){
System.out.println("Sotrue");
}
3)inti=1;
intj=2;
if(i==1||j==2)System.out.println("OK");
4)inti=1;
intj=2;i
f(i==1&|j==2)System.out.println("OK");
--------------------------------------------------------------------------------
Question15)
Whatwillbeoutputifyoutrytocompileandrunthefollowingcode,butthereis
nofilecalledHello.txtinthecurrentdirectory?
.
importjava.io.*;
publicclassMine{
publicstaticvoidmain(Stringargv[]){
Minem=newMine();
System.out.println(m.amethod());
}
publicintamethod(){
try{
FileInputStreamdis=newFileInputStream("Hello.txt");
}catch(FileNotFoundExceptionfne){
System.out.println("Nosuchfilefound");
return-1;
}catch(IOExceptionioe){}
finally{
System.out.println("Doingfinally");
}
return0;
}
}
1)Nosuchfilefound
2Nosuchfilefound,-1
3)Nosuchfilefound,Doingfinally,-1
4)0
--------------------------------------------------------------------------------
Question16)
Whichofthefollowingstatementsaretrue?
1)Methodscannotbeoverridentobemoreprivate
2)staticmethodscannotbeoverloaded
Staticmethodscannotbeoverridenbuttheycanbeoverloaded
3)privatemethodscannotbeoverloaded
4)Anoverloadedmethodcannotthrowexceptionsnotcheckedinthebaseclass
--------------------------------------------------------------------------------
Question17)
Whatwillhappenifyouattempttocompileandrunthefollowingcode?
classBase{}
classSubextendsBase{}
classSub2extendsBase{}
publicclassCEx{
publicstaticvoidmain(Stringargv[]){
Baseb=newBase();
Subs=(Sub)b;
}
}
1)Compileandrunwithouterror
2)CompiletimeException
3)RuntimeException
--------------------------------------------------------------------------------
Question18)
Whichofthefollowingstatementsaretrue?
1)System.out.println(-1>>>2);willoutputaresultlargerthan10无符号右移
2)System.out.println(-1>>2);willoutputapositivenumber输出-1
3)System.out.println(2>>1);willoutputthenumber1
4)System.out.println(1<<<2);willoutputthenumber4
--------------------------------------------------------------------------------
Question19)
Whatwillhappenwhenyouattempttocompileandrunthefollowingcode?
publicclassTuxextendsThread{
staticStringsName="vandeleur";
publicstaticvoidmain(Stringargv[]){
Tuxt=newTux();
t.piggy(sName);
System.out.println(sName);
}
publicvoidpiggy(StringsName){
sName=sName+"wiggy";
start();
}
publicvoidrun(){
for(inti=0;i<4;i++){
sName=sName+""+i;
}
}
}
1)Compiletimeerror
2)Compilationandoutputof"vandeleurwiggy"
3)Compilationandoutputof"vandeleurwiggy0123"
4)Compilationandoutputofeither"vandeleur","vandeleur0","vandeleur01""vandaleur012"or"vandaleur0123"
--------------------------------------------------------------------------------
Question20)
Whatwillbedisplayedwhenyouattempttocompileandrunthefollowingcode
//Codestart
importjava.awt.*;
publicclassButtextendsFrame{
publicstaticvoidmain(Stringargv[]){
ButtMyBut=newButt();
}
Butt(){
ButtonHelloBut=newButton("Hello");
ButtonByeBut=newButton("Bye");
add(HelloBut);
add(ByeBut);
setSize(300,300);
setVisible(true);}}//Codeend
1)Twobuttonssidebysideoccupyingalloftheframe,HelloontheleftandByeon
theright
2)OnebuttonoccupyingtheentireframesayingHello
3)OnebuttonoccupyingtheentireframesayingBye
4)TwobuttonsatthetopoftheframeonesayingHellotheothersayingBye
--------------------------------------------------------------------------------
Question21)
Whatwillbeoutputbythefollowingcode?
publicclassMyFor{
publicstaticvoidmain(Stringargv[]){
inti