SCJP试题-SCJPMockExam2

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



Question 58)
What will happen when you attempt to compile and run the following code.

public class Pvf{

static boolean Paddy;
public static void main(String argv[]){
System.out.println(Paddy);
}

}
1) Compile time error
2) compilation and output of false
3) compilation and output of true
4) compilation and output of null

Answer to Question 58)


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

Question 59)
Which of the following statements are true?

1) The x,y coordinates of an instance of MouseEvent can be obtained using the getX() and getY() methods
2) The x,y coordinates of an instance of MouseEvent can be obtained using the X and Y integer fields
3) The time of a MouseEvent can be extracted using the getTime() method
4) The time of a MouseEvent can be extracted using the when parameter of the MouseEvent constructor

Answer to Question 59)


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

Question 60)
Given the following code

import java.io.*;

public class Ppvg{
public static void main(String argv[]){
Ppvg p = new Ppvg();
p.fliton();
}
public int fliton(){
try{
FileInputStream din = new FileInputStream("Ppvg.java");
din.read();
}catch(IOException ioe){

System.out.println("flytwick");
return 99;
}fin");
return 99;
}finally{

System.out.println("fliton");
}

return -1;
}

}

Assuming the file Ppvg.java is available to be read which of the following statements are true if you try to compile and run the program?

1) The program will run and output only "flytwick"
2) The program will run and output only "fliton"
3) The program will run and output both "fliton" and "flytwick"
4) An error will occur at compile time because the method fliton attempts to return two values

Answer to Question 60)


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

Answers
Answer to Question 1)

Objective 4.5)

1) float f=1/3;
2) int i=1/3;
4) double d=999d;

The fact that option 3 does not compile may be a surprise. The problem is because the default type for a number with a decimal component is a double and not a float. The additional trailing d in the option with 999 doesn't help, but it doesn't harm.

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


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

Answer to Question 2)

Objective 4.3)

2) new

The option NULL (note the upper case letter) is definitely not a keyword. There is some discussion as to i. There is some discussion as to if null is a keyword but for the purpose of the exam you should probably assume it is a keyword.

The option instanceOf is a bit of a misleading option that would probably not occur on the exam. The real keyword is instanceof (note that the of has no capital letter O). I had the incorrect version in an earlier version of this tutorial as it looks more likely to my eyes. The instanceof keyword looks like a method, but it is actually an operator.

The option wend is probably valid in some other language to indicate the end of a while loop, but Java has no such keyword.

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


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

Answer to Question 3)

Objective 4.5)

1) System.out.println(1+1);
2) int i=2+'2';
Option 3 is not valid because single quotes are used to indicate a character constant and not a string. Several people have emailed me to say that option 3 will compile. When they eventually compiled the exact code they have agreed, it will not compile. Let me re-state that

String s="on"+'one';

Will NOT compile.

Option 4 will not compile because 255 is out of the range of a byte

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


视频学习

我考网版权与免责声明

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

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

最近更新

社区交流

考试问答