武汉智远软件有限责任公司.doc
《武汉智远软件有限责任公司.doc》由会员分享,可在线阅读,更多相关《武汉智远软件有限责任公司.doc(18页珍藏版)》请在冰点文库上搜索。
![武汉智远软件有限责任公司.doc](https://file1.bingdoc.com/fileroot1/2023-5/3/7020bfa8-9e2d-40fa-ab47-9417343c5cdd/7020bfa8-9e2d-40fa-ab47-9417343c5cdd1.gif)
选择题
1:
What will be the result of executing the following code?
// Filename; SuperclassX.java
package packageX;
public class SuperclassX
{
protected void superclassMethodX()
{
}
int superclassVarX;
}
// Filename SubclassY.java
1.package packageX.packageY;
2.
3.public class SubclassY extends SuperclassX
4.{
5.SuperclassX objX = new SubclassY();
6.SubclassY objY = new SubclassY();
7.void subclassMethodY()
8.{
9.objY.superclassMethodX();
10.int i;
11.i = objY.superclassVarX;
12.}
13.}
Choices:
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
2:
The following code is entire contents of a file called Example.java,causes precisely one error during compilation:
class SubClass extends BaseClass{
}
class BaseClass(){
String str;
public BaseClass(){
System.out.println(“ok”);}
public BaseClass(String s){
str=s;}}
public class Example{
public void method(){
SubClass s=new SubClass(“hello”);
BaseClass b=new BaseClass(“world”);
}
}
Which line would be cause the error?
ThefollowingcodeisentirecontentsofafilecalledExample.java,causespreciselyoneerrorduringcompilation:
classSubClassextendsBaseClass{
}
classBaseClass(){
Stringstr;
publicBaseClass(){
System.out.println(“ok”);}
publicBaseClass(Strings){
str=s;}}
publicclassExample{
publicvoidmethod(){
SubClasss=newSubClass(“hello”);
BaseClassb=newBaseClass(“world”);
}
}
Whichlinewouldbecausetheerror?
A.9
B.10
C.11
D.12
3:
鉴于Java的特点,它最适合的计算环境是
A.并行计算环境
B.分布式计算环境
C.高强度计算环境
D.开放式计算环境
4:
What will be printed when you execute the following code?
class X
{
Y b = new Y();
X()
{
System.out.print("X");
}
}
class Y
{
Y()
{
System.out.print("Y");
}
}
public class Z extends X
{
Y y = new Y();
Z()
{
System.out.print("Z");
}
public static void main(String[] args)
{
new Z();
}
}
Choices:
Whatwillbeprintedwhenyouexecutethefollowingcode?
classX
{
Yb=newY();
X()
{
System.out.print("X");
}
}
classY
{
Y()
{
System.out.print("Y");
}
}
publicclassZextendsX
{
Yy=newY();
Z()
{
System.out.print("Z");
}
publicstaticvoidmain(String[]args)
{
newZ();
}
}
Choices:
A.Z
B.YZ
C.XYZ
D.YXYZ
5:
Given the following class definition:
class A{
protected int i;
A(int i){
this.i=i;
}
}
which of the following would be a valid inner class for this class?
Select valid answer:
Giventhefollowingclassdefinition:
classA{
protectedinti;
A(inti){
this.i=i;
}
}
whichofthefollowingwouldbeavalidinnerclassforthisclass?
Selectvalidanswer:
A.classB{}
B.classBextendsA{}
C.classBextendsA{B(){System.out.println(“i=”+i);}}
D.classB{classA{}}
6:
下述程序代码中有语法错误的行是( )。
int i,ia[10],ib[10]; /*第一行*/
for (i=0;i<=9;i++) /*第2行*/
ia[i]=0; /*第3行*/
ib=ia; /*第4行*/
下述程序代码中有语法错误的行是()。
inti,ia[10],ib[10];/*第一行*/
for(i=0;i<=9;i++)/*第2行*/
ia[i]=0;/*第3行*/
ib=ia;/*第4行*/
A.第1行
B.第2行
C.第3行
D.第4行
7:
Give this class outline:
class Example{
private int x;
//rest of class body…
}
Assuming that x invoked by the code java Example, which statement can made x be directly accessible in main() method of Example.java?
Givethisclassoutline:
classExample{
privateintx;
//restofclassbody…
}
AssumingthatxinvokedbythecodejavaExample,whichstatementcanmadexbedirectlyaccessibleinmain()methodofExample.java?
A.Changeprivateintxtopublicintx
B.changeprivateintxtostaticintx
C.Changeprivateintxtoprotectedintx
D.changeprivateintxtofinalintx
8:
假定a和b为int型变量,则执行下述语句组后,b的值为
a=1;
b=10;
do
{
b-=a;
a++;
}while(b--<0);
A.9
B.-2
C.-1
D.8
9:
public class OuterClass {
private double d1 = 1.0;
//insert code here
}
You need to insert an inner class declaration at line 3. Which two inner class declarations are
valid?
publicclassOuterClass{
privatedoubled1=1.0;
//insertcodehere
}
Youneedtoinsertaninnerclassdeclarationatline3.Whichtwoinnerclassdeclarationsare
valid?
A.classInnerOne{publicstaticdoublemethoda(){returnd1;}}
B.publicclassInnerOne{staticdoublemethoda(){returnd1;}}
C.privateclassInnerOne{doublemethoda(){returnd1;}}
D.staticclassInnerOne{protecteddoublemethoda(){returnd1;}}
10:
WhicharenotJavakeywords?
A.TRUE
B.const
C.super
D.void
11:
Inthefollowingpiecesofcode,whichonewillcompilewithoutanyerror?
A.StringBuffersb1="abcd";
B.Booleanb=newBoolean("abcd");
C.C:
byteb=255;
D.floatfl=1.2;
12:
public class X{
public Object m(){
Object o = new Float(3.14F);//line 3
Object [] oa = new Object[1];//line 4
oa[0] = o;//line 5
o=null;//line 6
return oa[0];//line 7
}
}
When is the Float object, created in line 3,eligible for garbage collection?
publicclassX{
publicObjectm(){
Objecto=newFloat(3.14F);//line3
Object[]oa=newObject[1];//line4
oa[0]=o;//line5
o=null;//line6
returnoa[0];//line7
}
}
WhenistheFloatobject,createdinline3,eligibleforgarbagecollection?
A.justafterline5.
B.justafterline6
C.justafterline7(thatis,asthemethodreturns)
D.neverinthismethod
13:
Give the following java source fragement:
//point x
public class Interesting{
//do something
}
Which statement is correctly Java syntax at point x?
Givethefollowingjavasourcefragement:
//pointx
publicclassInteresting{
//dosomething
}
WhichstatementiscorrectlyJavasyntaxatpointx?
A.publicclassMyClass{//dootherthing…}
B.staticintPI=3.14
C.classMyClass{//dosomething…}
D.none
14:
Whichofthefollowingstatementsarenotlegal?
A.longl=4990;
B.inti=4L;
C.doubled=34.4;
D.doublet=0.9F.
15:
What will happen when you attempt to compile and run the following code?
int Output = 10;
boolean b1 = false;
if((b1 == true) && ((Output += 10) == 20))
{
System.out.println("We are equal " + Output);
}
else
{
System.out.println("Not equal!
" + Output);
}
Choices:
Whatwillhappenwhenyouattempttocompileandrunthefollowingcode?
intOutput=10;
booleanb1=false;
if((b1==true)&&((Output+=10)==20))
{
System.out.println("Weareequal"+Output);
}
else
{
System.out.println("Notequal!
"+Output);
}
Choices:
A.Compilationerror,attemptingtoperformbinarycomparisononlogicaldatatype
B.Compilationandoutputof"Weareequal10".
C.Compilationandoutputof"Notequal!
20".
D.Compilationandoutputof"Notequal!
10".
16:
What will be the result of executing the following code?
boolean a = true;
boolean b = false;
boolean c = true;
if (a == true)
if (b == true)
if (c == true) System.out.println("Some things are true in this world");
else System.out.println("Nothing is true in this world!
");
else if (a && (b = c)) System.out.println("It's too confusing to tell what is true and what is false");
else System.out.println("Hey this won't compile");
Choices:
Whatwillbetheresultofexecutingthefollowingcode?
booleana=true;
booleanb=false;
booleanc=true;
if(a==true)
if(b==true)
if(c==true)System.out.println("Somethingsaretrueinthisworld");
elseSystem.out.println("Nothingistrueinthisworld!
");
elseif(a&&(b=c))System.out.println("It'stooconfusingtotellwhatistrueandwhatisfalse");
elseSystem.out.println("Heythiswon'tcompile");
Choices:
A.Thecodewon'tcompile
B."Somethingsaretrueinthisworld"willbeprinted
C."Heythiswon'tcompile"willbeprinted
D.Noneofthese
17:
给出下面的代码片断。
。
。
下面的哪些陈述为错误的?
1) public void create() {
2) Vector myVect;
3) myVect = new Vector();
4) }
给出下面的代码片断。
。
。
下面的哪些陈述为错误的?
1)publicvoidcreate(){
2)VectormyVect;
3)myVect=newVector();
4)}
A.第二行的声明不会为变量myVect分配内存空间。
B.第二行语句创建一个Vector类对象。
C.第三行语句创建一个Vector类对象。
D.第三行语句为一个Vector类对象分配内存空间
18:
Whichstatementaboutlisteneristrue?
A.Mostcomponentallowmultiplelistenerstobeadded.
B.Ifmultiplelistenerbeaddtoasinglecomponent,theeventonlyaffectedonelistener.
C.Componentdon?
tallowmultiplelistenerstobeadd.
D.none
19:
Select valid identifier of Java:
Selectvalididentifi