Java认证模拟试题
来源:优易学  2011-11-28 18:03:22   【优易学:中国教育考试门户网】   资料下载   IT书店


question 31) 
what will happen when you attempt to compile and run the following code? 
public class holt extends thread{ 
private string sthreadname; 
public static void main(string argv[]){ 
holt h = new holt(); 
h.go(); 

holt(){} 
holt(string s){ 
sthreadname = s; 

public string getthreadname(){ 
return sthreadname; 

public void go(){ 
holt first = new holt('first'); 
first.start(); 
holt second = new holt('second'); 
second.start(); 

public void start(){ 
for(int i = 0; i < 2; i ++){ 
system.out.println(getthreadname() +i); 
try{ 
thread.sleep(100); 
} catch(interruptedexception e){system.out.println(e.getmessage());} 



1) compile time error 
2) output of first0, second0, first0, second1 
3) output of first0, first1, second0, second1 
4) runtime error 
answer to question 31 

-------------------------------------------------------------------------------- 
question 32) 
an applet has its layout manager set to the default of flowlayout. what code would be correct to change to another layout manager. 
1) setlayoutmanager(new gridlayout()); 
2) setlayout(new gridlayout(2,2)); 
3) setgridlayout(2,2); 
4) setborderlayout(); 
answer to question 32 

-------------------------------------------------------------------------------- 
question 33) 
what will happen when you attempt to compile and run the following code?. 
class background implements runnable{ 
int i=0; 
public int run(){ 
while(true){

question 45 
what will happen when you try compiling and running this code? 
public class ref{ 
public static void main(string argv[]){ 
ref r = new ref(); 
r.amethod(r); 

public void amethod(ref r){ 
int i=99; 
multi(r); 
system.out.println(i); 

public void multi(ref r){ 
r.i = r.i*2; 


1) error at compile time 
2) an output of 99 
3) an output of 198 
4) an error at runtime 
answer to question 45 

-------------------------------------------------------------------------------- 
question 46) 
you need to create a class that will store unique object elements. you do not need to sort these elements but they must be unique. 
what interface might be most suitable to meet this need? 
1)set 
2)list 
3)map 
4)vector 

answer to question 46 

-------------------------------------------------------------------------------- 
question 47) 
which of the following will successfully create an instance of the vector class and add an element? 
1) vector v=new vector(99); 
v[1]=99; 

2) vector v=new vector(); 
v.addelement(99); 

3) vector v=new vector(); 
v.add(99); 

4 vector v=new vector(100); 
v.addelement('99'); 
answer to question 47 

-------------------------------------------------------------------------------- 
question 48) 
you have created a simple frame and overridden the paint method as follows 
public void paint(graphics g){ 
g.drawstring('dolly',50,10); 

what will be the result when you attempt to compile and run the program? 
1) the string 'dolly' will be displayed at the centre of the frame 
2) an error at compilation complaining at the signature of the paint method 
3) the lower part of the word dolly will be seen at the top of the frame, with the top hidden. 
4) the string 'dolly' will be shown at the bottom of the frame. 
answer to question 48 

-------------------------------------------------------------------------------- 
question 49) 
what will be the result when you attempt to compile this program? 
public class rand{ 
public static void main(string argv[]){ 
int irand; 
irand = math.random(); 
system.out.println(irand); 

1) compile time error referring to a cast problem 
2) a random number between 1 and 10 

3) a random number between 0 and 1
4) a compile time error about random being an unrecognised method

answer to question 49

question 56) 
you are using the gridbaglayout manager to place a series of buttons on a frame. you want to make the size of one of the buttons bigger than the text it contains. which of the following will allow you to do that? 
1) the gridbaglayout manager does not allow you to do this 
2) the setfill method of the gridbaglayout class 
3) the setfill method of the gridbagconstraints class 
4) the fill field of the gridbagconstraints class 

answer to question 56 

-------------------------------------------------------------------------------- 
question 57) 
which of the following most closely describes a bitset collection? 
1) a class that contains groups of unique sequences of bits 
2) a method for flipping individual bits in instance of a primitive type 
3) an array of boolean primitives that indicate zeros or ones 
4) a collection for storing bits as on-off information, like a vector of bits 
answer to question 57 

-------------------------------------------------------------------------------- 
question 58) 
you have these files in the same directory. what will happen when you attempt to compile and run class1.java if you have not already compiled base.java 
//base.java 
package base; 
class base{ 
protected void amethod(){ 
system.out.println('amethod'); 
}//end of amethod 
}//end of class base 
package class1; 
//class1.java 
public class class1 extends base{ 
public static void main(string argv[]){ 
base b = new base(); 
b.amethod(); 
}//end of main 
}//end of class1 


1) compile error: methods in base not found 
2) compile error: unable to access protected method in base class 
3) compilation followed by the output 'amethod' 
4)compile error: superclass class1.base of class class1.class1 not found 
answer to question 58 

-------------------------------------------------------------------------------- 
question 59) 
what will happen when you attempt to compile and run the following code 
class base{ 
private void amethod(int ibase){ 
system.out.println('base.amethod');

上一页  [1] [2] 

责任编辑:小草

文章搜索:
 相关文章
热点资讯
热门课程培训