📄 scjp-1.htm
字号:
<TD vAlign=top width="13%"><FONT face=Courier>goto </FONT></TD>
<TD vAlign=top width="13%"><FONT face=Courier>package</FONT></TD>
<TD vAlign=top width="13%"><FONT face=Courier>throws</FONT></TD></TR>
<TR>
<TD vAlign=top width="13%"><FONT face=Courier>close </FONT></TD>
<TD vAlign=top width="13%"><FONT face=Courier>if</FONT></TD>
<TD vAlign=top width="13%"><FONT face=Courier>private</FONT></TD>
<TD vAlign=top width="13%"><FONT face=Courier>transient</FONT></TD></TR>
<TR>
<TD vAlign=top width="13%"><FONT face=Courier>const</FONT></TD>
<TD vAlign=top width="13%"><FONT face=Courier>implements</FONT></TD>
<TD vAlign=top width="13%"><FONT face=Courier>protected</FONT></TD>
<TD vAlign=top width="13%"><FONT face=Courier>try</FONT></TD></TR>
<TR>
<TD vAlign=top width="13%"><FONT face=Courier>continue</FONT></TD>
<TD vAlign=top width="13%"><FONT face=Courier>import</FONT></TD>
<TD vAlign=top width="13%"><FONT face=Courier>public</FONT></TD>
<TD vAlign=top width="13%"><FONT face=Courier>void</FONT></TD></TR>
<TR>
<TD vAlign=top width="13%"><FONT face=Courier>default</FONT></TD>
<TD vAlign=top width="13%"><FONT face=Courier>instanceof</FONT></TD>
<TD vAlign=top width="13%"><FONT face=Courier>return</FONT></TD>
<TD vAlign=top width="13%"><FONT face=Courier>volatile</FONT></TD></TR>
<TR>
<TD vAlign=top width="13%">do</TD>
<TD vAlign=top width="13%"><FONT face=Courier>integer</FONT></TD>
<TD vAlign=top width="13%"><FONT face=Courier>short</FONT></TD>
<TD vAlign=top width="13%"><FONT
face=Courier>while</FONT></TD></TR></TBODY></TABLE>
<P>Select all valid answers.
<OL type=a>
<LI>superclass
<LI>goto
<LI>open
<LI>close
<LI>integer
<LI>goto, import
<LI>goto, superclass, open, close
<LI>they are all valid keywords </LI></OL>
<P><B>Question 10</B>: Which of the following represents an octal number?
<P>Select all that apply.
<OL type=a>
<LI>0x12
<LI>32O
<LI>032
<LI>(octal)2
<LI>1 </LI></OL>
<P><B>Question 11</B>: What will appear in the standard output when you
run the Tester class?
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>class Tester {</FONT>
<P><FONT face=Courier>int var;</FONT>
<DIR><FONT face=Courier>Tester(double var) {</FONT>
<DIR><FONT face=Courier>this.var = (int)var;</FONT></DIR><FONT
face=Courier>}</FONT>
<P><FONT face=Courier>Tester(int var) {</FONT>
<DIR><FONT face=Courier>this("hello");</FONT></DIR><FONT
face=Courier>}</FONT>
<P><FONT face=Courier>Tester(String s) {</FONT>
<DIR><FONT face=Courier>this();</FONT>
<P><FONT face=Courier>System.out.println(s);</FONT></P></DIR><FONT
face=Courier>}</FONT>
<P><FONT face=Courier>Tester() {</FONT>
<DIR><FONT
face=Courier>System.out.println("good-bye");</FONT></DIR><FONT
face=Courier>}</FONT>
<P><FONT face=Courier>public static void main(String[] args)
{</FONT>
<DIR><FONT face=Courier>Tester t = new Tester(5);</FONT></DIR><FONT
face=Courier>}</FONT></DIR><FONT
face=Courier>}</FONT></TD></TR></TBODY></TABLE>
<OL type=a>
<LI>nothing
<LI>"hello"
<LI>5
<LI>"hello" followed by "good-bye"
<LI>"good-bye" followed by "hello" </LI></OL>
<P><B>Question 12</B>: Write a line of code to use the String抯 <FONT
face=Courier>substring()</FONT> method to obtain the substring "lip" from
a String instance named <FONT face=Courier>s</FONT> that is set to
"tulip".
<P>Fill in the blank.
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center> </TD></TR></TBODY></TABLE><FONT
face=Courier> </FONT>
<P><B>Question 13</B>: There are a number of labels in the source code
below. These are labeled <FONT face=Courier>a</FONT> through <FONT
face=Courier>j</FONT>. Which label identifies the earliest point where,
after that line has executed, the object referred to by the variable <FONT
face=Courier>first</FONT> may be garbage collected?
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>class Riddle {</FONT>
<DIR><FONT face=Courier>public static void main(String[] args)
{</FONT>
<DIR><FONT face=Courier>String first, second;</FONT>
<P><FONT face=Courier>String riddle;
<P>if (args.length < 2)
<P>return; a: first = new String(args[0]);
<P>b: second = new String(args[1]);
<P>c: riddle = "When is a " + first;
<P>d: first = null;
<P>e: riddle += " like a " + second + "?";
<P>f: second = null;
<P>g: System.out.println(riddle);
<P>h: args[0] = null;
<P>i: args[1] = null;
<P>j:
<DIR>}</DIR>}</FONT></DIR></DIR></TD></TR></TBODY></TABLE>Select the one
right answer.
<P>
<OL type=a>
<LI><FONT face=Courier>d:</FONT>
<LI><FONT face=Courier>e:</FONT>
<LI><FONT face=Courier>h:</FONT>
<LI><FONT face=Courier>i:</FONT>
<LI><FONT face=Courier>j:</FONT> </LI></OL>
<P><B>Question 14</B>: What are the range of values for a variable of type
<TT>byte</TT>?
<P>Select the one right answer.
<OL type=a>
<LI>-2<SUP>7</SUP> to 2<SUP>7</SUP> - 1
<LI>0 to 2<SUP>7</SUP>
<LI>-2<SUP>15</SUP> to 2<SUP>15</SUP>
<LI>-2<SUP>15</SUP> to 2<SUP>15</SUP> -1
<LI>-2<SUP>15</SUP> - 1 to 2<SUP>15</SUP> </LI></OL>
<P><B>Question 15</B>: What will happen when you try to compile and run
the following program?
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>class Car {</FONT>
<DIR><FONT face=Courier>int milesPerGallon;</FONT>
<P><FONT face=Courier>int index;</FONT>
<P><FONT face=Courier>Car(int mpg) {</FONT>
<DIR><FONT face=Courier>milesPerGallon = mpg;</FONT>
<P><FONT face=Courier>index = 0;</FONT></P></DIR><FONT
face=Courier>}</FONT>
<P><FONT face=Courier>Car() {</FONT>
<P><FONT face=Courier>}</FONT>
<P><FONT face=Courier>public static void main(String[] args)
{</FONT>
<DIR><FONT face=Courier>int index;</FONT>
<P><FONT face=Courier>Car c = new Car(25);</FONT>
<P><FONT face=Courier>if (args.length > 0)</FONT>
<DIR><FONT face=Courier>if (args[index].equals("Hiway"))</FONT>
<DIR><FONT face=Courier>milesPerGallon*= 2;</FONT> <FONT
face=Courier>System.out.println("mpg: " +
milesPerGallon);</FONT></DIR><FONT face=Courier>}</FONT></DIR><FONT
face=Courier>} </FONT></DIR></DIR></TD></TR></TBODY></TABLE>Select
the one right answer.
<OL type=a>
<LI>The code compiles and displays "mpg: 50" if the command-line
argument is "Hiway". If the command-line argument is not "Hiway", the
code displays "mpg: 25".
<LI>The code compiles and displays "mpg: 50" if the command-line
argument is "Hiway". If the command-line argument is not "Hiway", the
code throws an ArrayIndexOutOfBoundsException.
<LI>The code does not compile because the automatic variable named <FONT
face=Courier>index</FONT> has not been initialized.
<LI>The code does not compile because <FONT
face=Courier>milesPerGallon</FONT> has not been initialized.
<LI>The code does not compile because the no-args constructor is not
written correctly. </LI></OL>
<P><B>Question 16</B>: What will happen when you compile and run this
program:
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>class Array {</FONT>
<DIR><FONT face=Courier>public static void main(String[] args)
{</FONT>
<DIR><FONT face=Courier>int length = 100;</FONT>
<P><FONT face=Courier>int[] d = new int[length];</FONT>
<P><FONT face=Courier>for (int index = 0; index < length;
index++) </FONT>
<DIR><FONT face=Courier>System.out.println(d[index]);</FONT> <FONT
face=Courier>}</FONT></DIR><FONT
face=Courier>}</FONT></DIR></DIR></TD></TR></TBODY></TABLE>Select the one
right answer.
<OL type=a>
<LI>The code will not compile because the <FONT
face=Courier>int[]</FONT> array is not declared correctly.
<LI>The code will compile but will throw an
IndexArrayOutOfBoundsException when it runs and nothing will appear in
the standard output.
<LI>The code will display the numbers 0 through 99 in the standard
output, and then throw an IndexOutOfBoundsException.
<LI>The code will compile but the <FONT face=Courier>println()</FONT>
method will throw a NoSuchMethodException.
<LI>This code will work fine and display 100 zeroes in the standard
output. </LI></OL>
<P><B>Question 17</B>: What is the result of attempting to compile and run
the following class?
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>class Ar {</FONT>
<DIR><FONT face=Courier>public static void main(String[] args)
{</FONT>
<DIR><FONT face=Courier>int[] seeds = new int[3];</FONT>
<P><FONT face=Courier>for (int i = 0; i < seeds.length;
i++)</FONT>
<DIR><FONT face=Courier>System.out.println(i);</FONT> <FONT
face=Courier>}</FONT></DIR><FONT
face=Courier>}</FONT></DIR></DIR></TD></TR></TBODY></TABLE>Select all
valid answers.
<P>
<OL type=a>
<LI>0
<LI>1
<LI>2
<LI>3
<LI>the program does not compile because the seeds array is not
initialized </LI></OL>
<P><B>Question 18</B>: What method name can you use from the applet to
read a String passed to an applet via the <FONT
face=Courier><param></FONT> tag? (Supply the method name only,
without parameters.)
<P>Fill in the blank.
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT
face=Courier> </FONT></TD></TR></TBODY></TABLE>
<P><B>Question 19</B>: Given these class definitions:
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>class Superclass { }</FONT>
<P><FONT face=Courier>class Subclass1 extends Superclass {
}</FONT></P></TD></TR></TBODY></TABLE>and these objects:
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>Superclass a = new
Superclass();</FONT>
<P><FONT face=Courier>Subclass1 b = new
Subclass1();</FONT></P></TD></TR></TBODY></TABLE>which of the following
explains the result of the statement:
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>a =
b;</FONT></TD></TR></TBODY></TABLE>
<P>Select the one right answer.
<P>
<OL type=a>
<LI>Illegal at compile time
<LI>Legal at compile time but possibly illegal at runtime
<LI>Definitely legal at runtime </LI></OL>
<P><B><A name=no20>Question 20</A></B>: Given these class definitions:
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>class Superclass { }</FONT>
<P><FONT face=Courier>class Subclass1 extends Superclass { }</FONT>
<P><FONT face=Courier>class Subclass2 extends Superclass {
}</FONT></P></TD></TR></TBODY></TABLE>and these objects:
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>Superclass a = new
Superclass();</FONT>
<P><FONT face=Courier>Subclass1 b = new Subclass1();</FONT>
<P><FONT face=Courier>Subclass2 c = new
Subclass2();</FONT></P></TD></TR></TBODY></TABLE>which of the following
explains the result of the statement:
<TABLE width="100%" border=1>
<TBODY>
<TR>
<TD vAlign=center><FONT face=Courier>b =
(Subclass1)c;</FONT></TD></TR></TBODY></TABLE>Select the one right answer.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -