⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scjp试题-scjpmockexam4.txt

📁 包括多年scjp认证考试的很多题库及答案
💻 TXT
📖 第 1 页 / 共 5 页
字号:




Question 22) 

Which statement is true of the following code? 

public class Agg{ 
public static void main(String argv[]){ 
Agg a = new Agg(); 
a.go(); 
} 
public void go(){ 
DSRoss ds1 = new DSRoss("one"); 
ds1.start(); 
} 
} 

class DSRoss extends Thread{ 
private String sTname=""; 
DSRoss(String s){ 
sTname = s; 
} 
public void run(){ 
notwait(); 
System.out.println("finished"); 
} 
public void notwait(){ 
while(true){ 
try{ 
System.out.println("waiting"); 
wait(); 
}catch(InterruptedException ie){} 
System.out.println(sTname); 
notifyAll(); 
} 
} 

} 

1) It will cause a compile time error 
2) Compilation and output of "waiting" 
3) Compilation and output of "waiting" followed by "finished" 
4) Runtime error, an exception will be thrown 



Answer to Question 22  


-------------------------------------------------------------------------------- 

Question 23) 

Which of the following methods can be legally inserted in place of the comment //Method Here ?  

class Base{ 
public void amethod(int i) { } 
} 

public class Scope extends Base{ 
public static void main(String argv[]){ 
} 
//Method Here 
} 
1) void amethod(int i) throws Exception {}  
2) void amethod(long i)throws Exception {}  
3) void amethod(long i){}  
4) public void amethod(int i) throws Exception {}  

Answer to Question 23  


-------------------------------------------------------------------------------- 

Question 24) 

Which of the following will output -4.0  

1) System.out.println(Math.floor(-4.7));  
2) System.out.println(Math.round(-4.7));  
3) System.out.println(Math.ceil(-4.7));  
4) System.out.println(Math.min(-4.7));  

Answer to Question 24  


-------------------------------------------------------------------------------- 

Question 25) 

What will happen if you attempt to compile and run the following code?  

Integer ten=new Integer(10); 
Long nine=new Long (9); 
System.out.println(ten + nine); 
int i=1; 
System.out.println(i + ten); 
1) 19 followed by 20  
2) 19 followed by 11  
3) Error: Can’t convert java lang Integer  
4) 10 followed by 1  

Answer to Question 25  


-------------------------------------------------------------------------------- 

Question 26) 

If you run the code below, what gets printed out?  

String s=new String("Bicycle"); 
int iBegin=1; 
char iEnd=3; 
System.out.println(s.substring(iBegin,iEnd)); 
1) Bic  
2) ic  
3) icy  
4) error: no method matching substring(int,char)  

Answer to Question 26  


-------------------------------------------------------------------------------- 

Question 27) 
If you wanted to find out where the position of the letter v (ie return 2) in the string s  
containing "Java", which of the following could you use?  

1) mid(2,s);  
2) charAt(2);  
3) s.indexOf(’v’);  
4) indexOf(s,’v’);  

Answer to Question 27  


-------------------------------------------------------------------------------- 

Question 28) 
Given the following declarations  

String s1=new String("Hello") 
String s2=new String("there"); 
String s3=new String(); 
Which of the following are legal operations?  

1) s3=s1 + s2;  
2) s3=s1-s2;  
3) s3=s1 & s2;  
4) s3=s1 && s2  

Answer to Question 28  


-------------------------------------------------------------------------------- 

Question 29) 
What is the result of the following operation?  

System.out.println(4 | 3);  

1) 6  
2) 0  
3) 1  
4) 7  

Answer to Question 29  


-------------------------------------------------------------------------------- 

Question 30) 
public class MyClass1 { 
public static void main(String argv[]){ } 
/*Modifier at XX */ class MyInner {} 
} 
What modifiers would be legal at XX in the above code?  

1) public  
2) private  
3) static  
4) friend  

Answer to Question 30  


-------------------------------------------------------------------------------- 

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?.  

1) It will compile and the run method will print out the increasing value of i.  
2) It will compile and calling start will print out the increasing value of i.  
3) The code will cause an error at compile time.  
4) Compilation will cause an error because while cannot take a parameter of true.  

class Background implements Runnable{  

int i=0;  
public int run(){  
while(true){  
i++;  
System.out.println("i="+i);  
} //End while 
return 1; 
}//End run  

}//End class 

Answer to Question 33  


-------------------------------------------------------------------------------- 

Question 34) 

Which of the following statements about this code are true? 

public class Morecombe{ 
public static void main(String argv[]){ 
Morecombe m = new Morecombe(); 
m.go(new Turing(){});  
} 
public void go(Turing t){ 
t.start(); 
} 

} 
class Turing extends Thread{ 
public void run(){ 
for(int i =0; i < 2; i++){ 
System.out.println(i); 
}  
}  

} 


1) Compilation error due to malformed parameter to go method 
2) Compilation error, class Turing has no start method 
3) Compilation and output of 0 followed by 1 
4) Compilation but runtime error 

Answer to Question 34  






Question 35) 

What will be the result when you attempt to compile and run the following code?.  

public class Conv{ 
public static void main(String argv[]){ 
Conv c=new Conv(); 
String s=new String("ello"); 
c.amethod(s); 
} 

public void amethod(String s){ 
char c=’H’; 
c+=s; 
System.out.println(c); 
} 
} 
1) Compilation and output the string "Hello"  
2) Compilation and output the string "ello"  
3) Compilation and output the string elloH  
4) Compile time error  

Answer to Question 35  


-------------------------------------------------------------------------------- 

Question 36) 
Given the following code, what test would you need to put in place of the comment line?  

//place test here  

to result in an output of  

Equal 
public class EqTest{ 
public static void main(String argv[]){ 
EqTest e=new EqTest(); 
} 

EqTest(){ 
String s="Java"; 
String s2="java"; 
//place test here { 
System.out.println("Equal"); 
}else 
{ 
System.out.println("Not equal"); 
} 
} 
} 
1) if(s==s2)  
2) if(s.equals(s2)  
3) if(s.equalsIgnoreCase(s2))  
4)if(s.noCaseMatch(s2))  

Answer to Question 36  


-------------------------------------------------------------------------------- 

Question 37) 
Given the following code  

import java.awt.*; 
public class SetF extends Frame{ 
public static void main(String argv[]){ 
SetF s=new SetF(); 
s.setSize(300,200); 
s.setVisible(true); 
} 

} 
How could you set the frame surface color to pink  

1)s.setBackground(Color.pink);  
2)s.setColor(PINK);  
3)s.Background(pink);  
4)s.color=Color.pink  

Answer to Question 37  


-------------------------------------------------------------------------------- 

Question 38) 

How can you change the current working directory using an instance of the File class called FileName?  
1) FileName.chdir("DirName")  
2) FileName.cd("DirName")  
3) FileName.cwd("DirName")  
4) The File class does not support directly changing the current directory.  

Answer to Question 38  


-------------------------------------------------------------------------------- 

Question 39) 
If you create a TextField with a constructor to set it to occupy 5 columns, what difference will it make if you use it with a proportional font (ie Times Roman) or a fixed pitch typewriter style font (Courier).  

1)With a fixed font you will see 5 characters, with a proportional it will depend on the width of the characters  
2)With a fixed font you will see 5 characters,with a proportional it will cause the field to expand to fit the text  
3)The columns setting does not affect the number of characters displayed  
4)Both will show exactly 5 characters  

Answer to Question 39  


-------------------------------------------------------------------------------- 

Question 40) 

Given the following code how could you invoke the Base constructor that will print out the string "base constructor";  

class Base{ 
Base(int i){ 
System.out.println("base constructor"); 
} 
Base(){ 
} 
} 

public class Sup extends Base{ 
public static void main(String argv[]){ 
Sup s= new Sup(); 
//One 
} 
Sup() 
{ 
//Two 
} 

public void derived() 
{ 
//Three 
} 
} 
1) On the line After //One put Base(10);  
2) On the line After //One put super(10);  
3) On the line After //Two put super(10);  
4) On the line After //Three put super(10);  

Answer to Question 40  


-------------------------------------------------------------------------------- 

Question 41) 
Given the following code what will be output?  

public class Pass{ 
static int j=20; 
public static void main(String argv[]){ 
int i=10; 
Pass p = new Pass(); 
p.amethod(i); 
System.out.println(i); 
System.out.println(j); 
} 

public void amethod(int x){ 
x=x*2; 
j=j*2; 
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -