📄 scjp-1.htm
字号:
<LI><FONT face=Courier>ceil()</FONT> and <FONT
face=Courier>round()</FONT>
<LI><FONT face=Courier>floor()</FONT> and <FONT
face=Courier>round()</FONT>
<LI><FONT face=Courier>ceil()</FONT> only
<LI><FONT face=Courier>floor()</FONT> only
<LI><FONT face=Courier>round()</FONT> only </LI></OL>
<P><FONT face=Courier></FONT>
<P><B>Question 33</B>: What methods does Java define in the Math class
specifically for trigonometric calculations?
<P>Select all valid answers.
<P>
<OL type=a>
<LI><FONT face=Courier>cos()</FONT>
<LI><FONT face=Courier>asin()</FONT>
<LI><FONT face=Courier>tan()</FONT>
<LI><FONT face=Courier>sin()</FONT>
<LI><FONT face=Courier>angle()</FONT> </LI></OL>
<P>
<P><B>Question 34</B>: What String instance method would return <FONT
face=Courier>true</FONT> when invoked like this:
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT
face=Courier>a.method(b);</FONT></TD></TR></TBODY></TABLE>where a =
"GROUNDhog" and b = "groundHOG"?
<P>Select the one right answer.
<P>
<OL type=a>
<LI><FONT face=Courier>equals()</FONT>
<LI><FONT face=Courier>toLowerCase()</FONT>
<LI><FONT face=Courier>toUpperCase()</FONT>
<LI><FONT face=Courier>equalsIgnoreCase()</FONT>
<LI>none of the above </LI></OL>
<P>
<P><B>Question 35</B>: At the end of these two lines of code:
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>String s = "hypertext";</FONT>
<P><FONT face=Courier>String t = s.substring(2,
5);</FONT></P></TD></TR></TBODY></TABLE>What does the object reference
<FONT face=Courier>t</FONT> contain?
<P>Select the one right answer.
<P>
<OL type=a>
<LI>"yper"
<LI>"ype"
<LI>"pert"
<LI>"per"
<LI>"perte" </LI></OL>
<P><B>Question 36</B>: What access control keyword should you use to allow
other classes to access a method freely within its package, but to
restrict classes outside of the package from accessing that method?
<P>Select all valid answers.
<P>
<OL type=a>
<LI><FONT face=Courier>public</FONT>
<LI><FONT face=Courier>protected</FONT>
<LI><FONT face=Courier>private</FONT>
<LI>do not supply an access control keyword </LI></OL>
<P><B>Question 37</B>: After these two lines of code:
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>String s = "Dolly ";</FONT>
<P><FONT face=Courier>String t = s.concat("Hello,
");</FONT></P></TD></TR></TBODY></TABLE>What characters will the object
reference <FONT face=Courier>t</FONT> contain?
<P>Select the one right answer.
<P>
<OL type=a>
<LI>"Hello, Dolly "
<LI>"Dolly Hello, "
<LI>"Hello, "
<LI>"Dolly "
<LI>none of the above </LI></OL>
<P>
<P><B>Question 38</B>: What does the following code do?
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>File f = new
File("hello.test");</FONT>
<P><FONT face=Courier>FileOutputStream out = new
FileOutputStream(f);</FONT></P></TD></TR></TBODY></TABLE>Select the one
right answer.
<P>
<OL type=a>Create a new file named "hello.test" if it does not yet
exist. It also opens the file so you can write to it and read from it.
<LI>Create a new file named "hello.test" if it does not yet exist. The
file is not opened.
<LI>Open a file named "hello.test" so that you can write to it and read
from it, but does not create the file if it does not yet exist.
<LI>Open a file named "hello.test" so that you can write to it but
cannot read from it.
<LI>Create an object that you can now use to create and open the file
named "hello.test," and write to and read from the file. </LI></OL>
<P><B>Question 39</B>: Which expressions are illegal?
<P>Select all valid answers.
<P>
<OL type=a>
<LI><FONT face=Courier>(true & true)</FONT>
<LI><FONT face=Courier>(4 & 5)</FONT>
<LI><FONT face=Courier>(int myInt = 0 > 3)</FONT>
<LI><FONT face=Courier>float myFloat = 40.0;</FONT>
<LI><FONT face=Courier>boolean b = (boolean)99;</FONT> </LI></OL>
<P><B><A name=no40>Question 40</A></B>: Which label name(s) are illegal?
<P>Select all valid answers.
<P>
<OL type=a>
<LI><FONT face=Courier>here:</FONT>
<LI><FONT face=Courier>_there:</FONT>
<LI><FONT face=Courier>this:</FONT>
<LI><FONT face=Courier>that:</FONT>
<LI><FONT face=Courier>2to1odds:</FONT> </LI></OL>
<P><B>Question 41</B>: Given this code:
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>import java.io.*;</FONT>
<P><FONT face=Courier></FONT>
<P><FONT face=Courier>class Write {</FONT>
<DIR><FONT face=Courier>public static void main(String[] args)
throws Exception {</FONT>
<DIR><FONT face=Courier>File file = new File("temp.test");</FONT>
<P><FONT face=Courier>FileOutputStream stream = new
FileOutputStream(file);</FONT>
<P><FONT face=Courier></FONT>
<P><FONT face=Courier>// write integers here. . .</FONT>
<P><FONT face=Courier></FONT> </P></DIR><FONT
face=Courier>}</FONT></DIR><FONT
face=Courier>}</FONT></TD></TR></TBODY></TABLE>How can you replace the
comment at the end of <FONT face=Courier>main()</FONT> with code that will
write the integers 0 through 9?
<P>Select the one right answer.
<P>a)
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>DataOutputStream filter = new
DataOutputStream(stream);</FONT>
<P><FONT face=Courier></FONT>
<P><FONT face=Courier>for (int i = 0; i < 10; i++)</FONT>
<DIR><FONT
face=Courier>filter.writeInt(i);</FONT></DIR></TD></TR></TBODY></TABLE>b)
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>for (int i = 0; i < 10;
i++)</FONT>
<DIR><FONT
face=Courier>file.writeInt(i);</FONT></DIR></TD></TR></TBODY></TABLE>c)
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>for (int i = 0; i < 10;
i++)</FONT>
<DIR><FONT
face=Courier>stream.writeInt(i);</FONT></DIR></TD></TR></TBODY></TABLE>d)
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>DataOutputStream filter = new
DataOutputStream(stream);</FONT>
<P><FONT face=Courier></FONT>
<P><FONT face=Courier>for (int i = 0; i < 10; i++)</FONT>
<DIR><FONT
face=Courier>filter.write(i);</FONT></DIR></TD></TR></TBODY></TABLE>e)
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>for (int i = 0; i < 10;
i++)</FONT>
<DIR><FONT
face=Courier>stream.write(i);</FONT></DIR></TD></TR></TBODY></TABLE>
<P><B>Question 42</B>: What keyword, when used in front of a method, must
also appear in front of the class?
<P>Fill in the blank.
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT
face=Courier> </FONT></TD></TR></TBODY></TABLE><B>Question 43</B>:
What letters get written to the standard output with the following code?
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>class Unchecked {</FONT>
<DIR><FONT face=Courier>public static void main(String[] args)
{</FONT>
<DIR><FONT face=Courier>try {</FONT>
<DIR><FONT face=Courier>method();</FONT></DIR><FONT face=Courier>}
catch (Exception e) {</FONT>
<P><FONT face=Courier>}</FONT></P></DIR><FONT face=Courier>}</FONT>
<P><FONT face=Courier></FONT>
<P><FONT face=Courier>static void method() {</FONT>
<DIR><FONT face=Courier>try {</FONT>
<DIR><FONT face=Courier>wrench();</FONT>
<P><FONT face=Courier>System.out.println("a");</FONT></P></DIR><FONT
face=Courier>} catch (ArithmeticException e) {</FONT>
<DIR><FONT face=Courier>System.out.println("b");</FONT></DIR><FONT
face=Courier>} finally {</FONT>
<DIR><FONT face=Courier>System.out.println("c");</FONT></DIR><FONT
face=Courier>}</FONT>
<P><FONT face=Courier>System.out.println("d");</FONT></P></DIR><FONT
face=Courier>}</FONT>
<P><FONT face=Courier></FONT>
<P><FONT face=Courier>static void wrench() {</FONT>
<DIR><FONT face=Courier>throw new
NullPointerException();</FONT></DIR><FONT
face=Courier>}</FONT></DIR><FONT
face=Courier>}</FONT></TD></TR></TBODY></TABLE>Select all valid answers.
<P>
<OL type=a>
<LI>"a"
<LI>"b"
<LI>"c"
<LI>"d"
<LI>none of these </LI></OL>
<P><B>Question 44</B>: What happens if the file "Ran.test" does not yet
exist and you attempt to compile and run the following code?
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>import java.io.*;</FONT>
<P><FONT face=Courier></FONT>
<P><FONT face=Courier>class Ran {</FONT>
<DIR><FONT face=Courier>public static void main(String[] args)
throws IOException {</FONT>
<DIR><FONT face=Courier>RandomAccessFile out = new
RandomAccessFile("Ran.test", "rw");</FONT>
<P><FONT
face=Courier>out.writeBytes("Ninotchka");</FONT></P></DIR><FONT
face=Courier>}</FONT></DIR><FONT
face=Courier>}</FONT></TD></TR></TBODY></TABLE>Select the one right
answer.
<P>
<OL type=a>
<LI>The code does not compile because RandomAccessFile is not created
correctly.
<LI>The code does not compile because RandomAccessFile does not
implement the <FONT face=Courier>writeBytes()</FONT> method.
<LI>The code compiles and runs but throws an IOException because
"Ran.test" does not yet exist.
<LI>The code compiles and runs but nothing appears in the file
"Ran.test" that it creates.
<LI>The code compiles and runs and "Ninotchka" appears in the file
"Ran.test" that it creates. </LI></OL>
<P><B>Question 45</B>: If you run the following code on a on a PC from the
directory <FONT face=Courier>c:\source</FONT>:
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>import java.io.*;</FONT>
<P><FONT face=Courier></FONT>
<P><FONT face=Courier>class Path {</FONT>
<DIR><FONT face=Courier>public static void main(String[] args)
throws Exception {</FONT>
<DIR><FONT face=Courier>File file = new File("Ran.test");</FONT>
<P><FONT
face=Courier>System.out.println(file.getAbsolutePath());</FONT></P></DIR><FONT
face=Courier>}</FONT></DIR><FONT
face=Courier>}</FONT></TD></TR></TBODY></TABLE>what do you expect the
output to be?
<P>Select the one right answer.
<P>
<OL type=a>
<LI><FONT face=Courier>Ran.test</FONT>
<LI><FONT face=Courier>source\Ran.test</FONT>
<LI><FONT face=Courier>c:\source\Ran.test</FONT>
<LI><FONT face=Courier>c:\source</FONT>
<LI><FONT face=Courier>null</FONT> </LI></OL>
<P><B>Question 46</B>: If you supply a target object when you create a new
Thread, as in:
<TABLE width="100%" border=1>
<TBODY>
<TR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -