JAVA认证格林模拟试题二(上)
来源:优易学  2009-11-28 15:02:00   【优易学:中国教育考试门户网】   资料下载   IT书店
文章页内部300*250广告位

 

question 21)

how does the set collection deal with duplicate elements?

1) an exception is thrown if you attempt to add an element with a duplicate value
2) the add method returns false if you attempt to add an element with a duplicate value
3) a set may contain elements that return duplicate values from a call to the equals method
4) duplicate values will cause an error at compile time

question 22)

what can cause a thread to stop executing?

1) the program exits via a call to system.exit(0);
2) another thread is given a higher priority
3) a call to the thread's stop method.
4) a call to the halt method of the thread class

 


question 23)

for a class defined inside a method, what rule governs access to the variables of the enclosing method?

1) the class can access any variable
2) the class can only access static variables
3) the class can only access transient variables
4) the class can only access final variables


question 24)


under what circumstances might you use the yield method of the thread class

1) to call from the currently running thread to allow another thread of the same or higher priority to run
2) to call on a waiting thread to allow it to run
3) to allow a thread of higher priority to run
4) to call from the currently running thread with a parameter designating which thread should be allowed to run


question 25)

what will happen when you attempt to compile and run the following code

public class hope{
public static void main(string argv[]){
hope h = new hope();
}

protected hope(){
for(int i =0; i <10; i ++){
system.out.println(i);
}
}
}

1) compilation error: constructors cannot be declared protected
2) run time error: constructors cannot be declared protected
3) compilation and running with output 0 to 10
4) compilation and running with output 0 to 9

question 26)

what will happen when you attempt to compile and run the following code

public class myswitch{
public static void main(string argv[]){
myswitch ms= new myswitch();
ms.amethod();
}


public void amethod(){
int k=10;
switch(k){
default: //put the default at the bottom, not here
system.out.println("this is the default output");
break;
case 10:
system.out.println("ten");
case 20:
system.out.println("twenty");
break;
}
}
}

1) none of these options
2) compile time error target of switch must be an integral type
3) compile and run with output "this is the default output"
4) compile and run with output of the single line "ten"

question 27)

which of the following is the correct syntax for suggesting that the jvm performs garbage collection

1) system.free();
2) system.setgarbagecollection();
3) system.out.gc();
4) system.gc();


question 28)


what will happen when you attempt to compile and run the following code

public class as{
int i = 10;
int j;
char z= 1;
boolean b;
public static void main(string argv[]){
as a = new as();
a.amethod();
}
public void amethod(){
system.out.println(j);
system.out.println(b);
}
}

1) compilation succeeds and at run time an output of 0 and false
2) compilation succeeds and at run time an output of 0 and true
3) compile time error b is not initialised
4) compile time error z must be assigned a char value

question 29)


what will happen when you attempt to compile and run the following code with the command line "hello there"

public class arg{
string[] myarg;
public static void main(string argv[]){
myarg=argv;
}

public void amethod(){
system.out.println(argv[1]);
}
}

1) compile time error
2) compilation and output of "hello"
3) compilation and output of "there"
4) none of the above


question 30)

what will happen when you attempt to compile and run the following code

public class streq{
public static void main(string argv[]){
streq s = new streq();
}
private streq(){
string s = "marcus";
string s2 = new string("marcus");
if(s == s2){
system.out.println("we have a match");
}else{
system.out.println("not equal");
}
}
}

1) compile time error caused by private constructor
2) output of "we have a match"
3) output of "not equal"
4) compile time error by attempting to compare strings using ==

上一页  [1] [2] [3] 

责任编辑:小草

收藏此页】【 】【打印】【回到顶部
计算机文章页底部500*200广告
文章搜索:
 相关文章
计算机底部580*90广告
文章页右侧第一330*280广告
计算机文章页资讯推荐
热点资讯
文章页330尺寸谷歌广告位
热门课程培训