浙大网新中研软件开发工程师笔试题.docx
《浙大网新中研软件开发工程师笔试题.docx》由会员分享,可在线阅读,更多相关《浙大网新中研软件开发工程师笔试题.docx(13页珍藏版)》请在冰豆网上搜索。
浙大网新中研软件开发工程师笔试题
浙大网新中研软件开发工程师笔试题
选择题
1:
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,becausegoingdownthehierarchywithoutcastingisnotallowed.
D.Thecodewillcompileifweputanexplicitcastatline6butwillthrowanexceptionatruntime.
2:
Aclassdesignrequiresthatamembervariableshouldbeaccessibleonlybysamepackage,whichmodiferwordshouldbeused?
A.protected
B.public
C.nomodifer
D.private
3:
Whatistheresultwhenyoucompileandrunthefollowingcode?
publicclassThrowsDemo
{
staticvoidthrowMethod()
{
System.out.println(InsidethrowMethod.);
thrownewIllegalAccessException(demo);
}
publicstaticvoidmain(Stringargs[])
{
try
{
throwMethod();
}
catch(IllegalAccessExceptione)
{
System.out.println(Caught+e);
}
}
}
Choices:
Whatistheresultwhenyoucompileandrunthefollowingcode?
publicclassThrowsDemo
{
staticvoidthrowMethod()
{
System.out.println(InsidethrowMethod.);
thrownewIllegalAccessException(demo);
}
publicstaticvoidmain(Stringargs[])
{
try
{
throwMethod();
}
catch(IllegalAccessExceptione)
{
System.out.println(Caught+e);
}
}
}
Choices:
A.Compilationerror
B.Runtimeerror
C.Compilesuccessfully,nothingisprinted.
D.InsidethrowMethod.followedbycaught:
java.lang.IllegalAccessExcption:
demo
4:
Inthefollowingcode,whichistheearlieststatement,wheretheobjectoriginallyheldine,maybegarbagecollected:
1.publicclassTest{
2.publicstaticvoidmain(Stringargs[]){
3.Employeee=newEmployee(Bob,48);
4.e.calculatePay();
5.System.out.println(e.printDetails());
6.e=null;
7.e=newEmployee(Denise,36);
8.e.calculatePay();
9.System.out.println(e.printDetails());
10.}
11.}
OnlyOne:
Inthefollowingcode,whichistheearlieststatement,wheretheobjectoriginallyheldine,maybegarbagecollected:
1.publicclassTest{
2.publicstaticvoidmain(Stringargs[]){
3.Employeee=newEmployee(Bob,48);
4.e.calculatePay();
5.System.out.println(e.printDetails());
6.e=null;
7.e=newEmployee(Denise,36);
8.e.calculatePay();
9.System.out.println(e.printDetails());
10.}
11.}
OnlyOne:
A.Line10
B.Line11
C.Line7
D.Line8
5:
Whatwillbetheresultofexecutingthefollowingcode?
publicstaticvoidmain(Stringargs[])
{
chardigit=a
for(inti=0;ii++)
{
switch(digit)
{
casex:
{
intj=0;
System.out.println(j);
}
default:
{
intj=100;
System.out.println(j);
}
}
}
inti=j;
System.out.println(i);
}
Choices:
Whatwillbetheresultofexecutingthefollowingcode?
publicstaticvoidmain(Stringargs[])
{
chardigit=a
for(inti=0;ii++)
{
switch(digit)
{
casex:
{
intj=0;
System.out.println(j);
}
default:
{
intj=100;
System.out.println(j);
}
}
}
inti=j;
System.out.println(i);
}
Choices:
A.100willbeprinted11times.
B.Thecodewillnotcompilebecausethevariableicannotbedeclaredtwicewithinthemain()method.
C.Thecodewillnotcompilebecausethevariablejcannotbedeclaredtwicewithintheswitchstatement.
D.Noneofthese.