SCJP试题-SCJPMockExam4

来源:java认证发布时间:2012-11-12 12:48:14java认证视频


Question 54)

Which statement is true of the following code?


public class Rpcraven{
public static void main(String argv[]){
Pmcraven pm1 = new Pmcraven("one");
pm1.run();
Pmcraven pm2 = new Pmcraven("two");
pm2.run();

}
}

class Pmcraven extends Thread{
private String sTname="";
Pmcraven(String s){
sTname = s;

}
public void run(){
for(int i =0; i < 2 ; i++){
try{
sleep(1000);
}catch(InterruptedException e){}

yield();
System.out.println(sTname);
}

}
}

1) Compile time error, class Rpcraven does not import java.lang.Thread
2) Output of One One Two Two
3) Output of One Two One Two
4) Compilation but no output at runtime


Answer to Question 54 


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

Question 55)
You are concerned that your program may attempt to use more memory than is available. To avoid this situation you want to ensure that the Java Virtual Machine will run its garbage collection just before you start a complex routine. What can you do to be certain that garbage collection will run when you want . 

1) You cannot be certain when garbage collection will run 
2) Use the Runtime.gc() method to force garbage collection 
3) Ensure that all the variables you require to be garbage collected are set to null 
4) Use the System.gc() method to force garbage collection 

Answer to Question 55 


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

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");
}
}



class Over extends Base{
public static void main(String argv[]){
Over o = new Over();
int iBase=0;
o.amethod(iBase);
}

public void amethod(int iOver){
System.out.println("Over.amethod");
}
}
1) Compile time error complaining that Base.amethod is private 
2) Runtime error complaining that Base.amethod is private 
3) Output of "Base.amethod"
4) Output of "Over.amethod" 


Answer to Question 59 


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

Question 60)
You are creating an applet with a Frame that contains buttons. You are using the GridBagLayout manager and you have added Four buttons. At the moment the buttons appear in the centre of the frame from left to right. You want them to appear one on top of the other going down the screen. What is the most appropriate way to do this. 


1) Set the gridy value of the GridBagConstraints class to a value increasing from 1 to 4 
2) set the fill value of the GridBagConstraints class to VERTICAL 
3) Set the ipady value of the GridBagConstraints class to a value increasing from 0 to 4 
4) Set the fill value of the GridBagLayouts class to GridBag.VERTICAL 

Answer to Question 60 

If you have a copy of the Roberts and Heller Java2 Guide that says the exam does not cover the GridBagLayout, this is an error. You can confirm this by looking at the online errata at 

http://www.sybex.com/cgi-bin/rd_err_temp.pl?2463err.html 


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

Answers

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

Answer 1)
Back to question 1) 
Objective 4.5)

5) int i=10; 

explanation: 
1) float f=1.3; 
Will not compile because the default type of a number with a floating point component is a double. This would compile with a cast as in 

float f=(float) 1.3 


2) char c="a"; 

Will not compile because a char (16 bit unsigned integer) must be defined with single quotes. This would compile if it were in the form 

char c=’a’; 

3) byte b=257; 

Will not compile because a byte is eight bits. Take of one bit for the sign component you can define numbers between 

-128 to +127 

4) a boolean value can either be true or false, null is not allowed


http://www.jchq.net/tutorial/04_05Tut.htm. 


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

Answer 2)
Back to question 2) 

Objective 4.1 

1) Can’t make static reference to void amethod. 

Because main is defined as static you need to create an instance of the class in order to call any non-static methods. Thus a typical way to do this would be. 


MyClass m=new MyClass(); 

m.amethod(); 


Answer 2 is an attempt to confuse because the convention is for a main method to be in the form 

String argv[] 

That argv is just a convention and any acceptable identifier for a string array can be used. Answers 3 and 4 are just nonsense.

http://www.jchq.net/tutorial/04_01Tut.htm



视频学习

我考网版权与免责声明

① 凡本网注明稿件来源为"原创"的所有文字、图片和音视频稿件,版权均属本网所有。任何媒体、网站或个人转载、链接转贴或以其他方式复制发表时必须注明"稿件来源:我考网",违者本网将依法追究责任;

② 本网部分稿件来源于网络,任何单位或个人认为我考网发布的内容可能涉嫌侵犯其合法权益,应该及时向我考网书面反馈,并提供身份证明、权属证明及详细侵权情况证明,我考网在收到上述法律文件后,将会尽快移除被控侵权内容。

最近更新

社区交流

考试问答