?? mindq's sun certified java programmer practice test.htm
字號:
16</TD>
<TD vAlign=top width="20%"><INPUT type=radio value=c name=Q19>c) <BR>1 2 3
4</TD>
<TD vAlign=top width="20%"><INPUT type=radio value=d name=Q19>d) <BR>1 2 3
4<BR>5 6 7 8<BR>9 10 11 12<BR>13 14 15 16</TD>
<TD vAlign=top width="20%"><INPUT type=radio value=e name=Q19>e)
<BR>1<BR>2 3 <BR>4 5 6 <BR>7 8 9 10</TD></TR></TBODY></TABLE>
<P></P>
<P><FONT size=4>20. Which of the following are legal declarations of a
two-dimensional array of integers?<BR><BR></FONT><INPUT type=checkbox
value=CheckBox name=Q20_a> a) <TT>int[5][5]a = new int[][]</TT>;<BR><INPUT
type=checkbox value=CheckBox name=Q20_b> b) <TT>int a = new int[5,5];</TT>
<BR><INPUT type=checkbox value=CheckBox name=Q20_c> c) <TT>int[]a[] = new
int[5][5];</TT><BR><INPUT type=checkbox value=CheckBox name=Q20_d> d)
<TT>int[][]a = new[5]int[5];</TT><BR><BR><BR><FONT size=4>21. Which of the
following are correct methods for initializing the array "dayhigh" with 7
values?<BR><BR></FONT><INPUT type=checkbox value=CheckBox name=Q21_a> a) <TT>int
dayhigh = { 24, 23, 24, 25, 25, 23, 21 };</TT><BR><INPUT type=checkbox
value=CheckBox name=Q21_b> b) <TT>int dayhigh[] = { 24, 23, 24, 25, 25, 23, 21
};</TT><BR><INPUT type=checkbox value=CheckBox name=Q21_c> c) <TT>int[] dayhigh
= { 24, 23, 24, 25, 25, 23, 21 };</TT><BR><INPUT type=checkbox value=CheckBox
name=Q21_d> d) <TT>int dayhigh [] = new int[24, 23, 24, 25, 25, 23,
21];</TT><BR><INPUT type=checkbox value=CheckBox name=Q21_e> e) <TT>int dayhigh
= new[24, 23, 24, 25, 25, 23, 21];</TT><BR><BR><BR><FONT size=4>22. If you want
subclasses to access, but not to override a superclass member method, what
keyword should precede the name of the superclass method?<BR><BR></FONT><INPUT
size=25 name=Q22><FONT size=4><BR><BR><BR>23. If you want a member variable to
not be accessible outside the current class at all, what keyword should precede
the name of the variable when declaring it?<BR><BR></FONT><INPUT size=25
name=Q23><FONT size=4><BR><BR><BR>24. Consider the code below:</FONT></P><PRE><BLOCKQUOTE>
public static void main( String args[] )
{ int a = 5;
System.out.println( cube( a ) );
}
int cube( int theNum )
{
return theNum * theNum * theNum;
}</BLOCKQUOTE>
</PRE>
<P>What will happen when you attempt to compile and run this code?<BR><BR><INPUT
type=radio value=a name=Q24>a) It will not compile because cube is already
defined in the java.lang.Math class.<BR><INPUT type=radio value=b name=Q24>b) It
will not compile because cube is not static.<BR><INPUT type=radio value=c
name=Q24>c) It will compile, but throw an arithmetic exception.<BR><INPUT
type=radio value=d name=Q24>d) It will run perfectly and print "125" to standard
output.<BR><BR><BR><FONT size=4>25. Given the variables defined below:</FONT>
</P>
<BLOCKQUOTE>
<P><TT>int one = 1;<BR>int two = 2;<BR>char initial = '2';<BR>boolean flag =
true;</TT> </P></BLOCKQUOTE>
<P><FONT size=4>Which of the following are valid?<BR></FONT><BR><INPUT
type=checkbox name=Q25_a>a) <TT>if( one ){}</TT><BR><INPUT type=checkbox
name=Q25_b>b) <TT>if( one = two ){}</TT><BR><INPUT type=checkbox name=Q25_c>c)
<TT>if( one == two ){}</TT><BR><INPUT type=checkbox name=Q25_d>d) <TT>if( flag
){}</TT><BR><INPUT type=checkbox name=Q25_e>e) <TT>switch( one
){}</TT><BR><INPUT type=checkbox name=Q25_f>f) <TT>switch( flag
){}</TT><BR><INPUT type=checkbox name=Q25_g>g) <TT>switch( initial
){}</TT><BR><BR><BR><FONT size=4>26. If val = 1 in the code below:</FONT></P><PRE><BLOCKQUOTE>
<CODE>switch( val ) </CODE>
<CODE>{ case 1: System.out.print( "P" );</CODE>
<CODE> case 2: </CODE>
<CODE> case 3: System.out.print( "Q" );</CODE>
<CODE> break;</CODE>
<CODE> case 4: System.out.print( "R" );</CODE>
<CODE> default: System.out.print( "S" );</CODE>
<CODE>}</CODE></BLOCKQUOTE>
</PRE>
<P><FONT size=4>Which values would be printed?<BR></FONT><BR><INPUT
type=checkbox value=CheckBox name=Q26_a> a) P<BR><INPUT type=checkbox
value=CheckBox name=Q26_b> b) Q<BR><INPUT type=checkbox value=CheckBox
name=Q26_c> c) R<BR><INPUT type=checkbox value=CheckBox name=Q26_d> d)
S<BR><BR><BR><FONT size=4>27. Assume that val has been defined as an
<TT>int</TT> for the code below:</FONT></P><PRE><BLOCKQUOTE>
<CODE>if( val > 4 ) </CODE>
<CODE>{ System.out.println( "Test A" );</CODE>
<CODE>}</CODE>
<CODE>else if( val > 9 ) </CODE>
<CODE>{ System.out.println( "Test B" );</CODE>
<CODE>}</CODE>
<CODE>else System.out.println( "Test C" );</CODE></BLOCKQUOTE>
</PRE>
<P><FONT size=4>Which values of <TT>val</TT> will result in "Test C" being
printed:</FONT></P>
<P><INPUT type=checkbox value=CheckBox name=Q27_a> a) <TT>val</TT> < 0
<BR><INPUT type=checkbox value=CheckBox name=Q27_b> b) <TT>val</TT> between 0
and 4 <BR><INPUT type=checkbox value=CheckBox name=Q27_c> c) <TT>val</TT>
between 4 and 9 <BR><INPUT type=checkbox value=CheckBox name=Q27_d> d)
<TT>val</TT> > 9 <BR><INPUT type=checkbox value=CheckBox name=Q27_e> e)
<TT>val</TT> = 0 <BR><INPUT type=checkbox value=CheckBox name=Q27_f> f) no
values for <TT>val</TT> will be satisfactory</P>
<P><FONT size=4>28. What exception might a <TT>wait()</TT> method
throw?<BR><BR></FONT><INPUT size=25 name=Q28><FONT size=4> <BR><BR><BR>29. For
the code:</FONT></P><PRE><BLOCKQUOTE>
<CODE>m = 0;</CODE>
<CODE>while( m++ < 2 )</CODE>
<CODE> System.out.println( m );</CODE></BLOCKQUOTE>
</PRE>
<P><FONT size=4>Which of the following are printed to standard
output?<BR></FONT><BR><INPUT type=checkbox value=CheckBox name=Q29_a> a)
0<BR><INPUT type=checkbox value=CheckBox name=Q29_b> b) 1<BR><INPUT
type=checkbox value=CheckBox name=Q29_c> c) 2<BR><INPUT type=checkbox
value=CheckBox name=Q29_d> d) 3<BR><INPUT type=checkbox value=CheckBox
name=Q29_e> e) Nothing and an exception is thrown<BR><BR><BR><FONT size=4>30.
Consider the code fragment below:</FONT></P><PRE><BLOCKQUOTE>
<CODE>outer: for( int i = 1; i <3; i++ )</CODE>
<CODE> { inner: for( j = 1; j < 3; j++ )</CODE>
<CODE> { if( j==2 )</CODE>
<CODE> continue outer;</CODE>
<CODE> System.out.println( "i = " +i ", j = " + j );</CODE>
<CODE> }</CODE>
<CODE> } </CODE></BLOCKQUOTE>
</PRE>
<P>Which of the following would be printed to standard output?<BR><BR><INPUT
type=checkbox value=CheckBox name=Q30_a> a) i = 1, j = 1<BR><INPUT type=checkbox
value=CheckBox name=Q30_b> b) i = 1, j = 2<BR><INPUT type=checkbox
value=CheckBox name=Q30_c> c) i = 1, j = 3<BR><INPUT type=checkbox
value=CheckBox name=Q30_d> d) i = 2, j = 1<BR><INPUT type=checkbox
value=CheckBox name=Q30_e> e) i = 2, j = 2<BR><INPUT type=checkbox
value=CheckBox name=Q30_f> f) i = 2, j = 3<BR><INPUT type=checkbox
value=CheckBox name=Q30_g> g) i = 3, j = 1<BR><INPUT type=checkbox
value=CheckBox name=Q30_h> h) i = 3, j = 2<BR><BR><BR><FONT size=4>31. Consider
the code below:</FONT></P><PRE><TT><CODE>void myMethod() </CODE></TT>
<TT><CODE>{ try </CODE></TT>
<TT><CODE> { </CODE></TT>
<TT><CODE> fragile();</CODE></TT>
<TT><CODE> }</CODE></TT>
<TT><CODE> catch( NullPointerException npex ) </CODE></TT>
<TT><CODE> { </CODE></TT>
<TT><CODE> System.out.println( "NullPointerException thrown " );</CODE></TT>
<TT><CODE> }</CODE></TT>
<TT><CODE> catch( Exception ex ) </CODE></TT>
<TT><CODE> { </CODE></TT>
<TT><CODE> System.out.println( "Exception thrown " );</CODE></TT>
<TT><CODE> }</CODE></TT>
<TT><CODE> finally </CODE></TT>
<TT><CODE> { </CODE></TT>
<TT><CODE> System.out.println( "Done with exceptions " ); </CODE></TT>
<TT><CODE> }</CODE></TT>
<TT><CODE> System.out.println( "myMethod is done" );</CODE></TT>
<TT><CODE>}</CODE></TT></PRE>
<P><FONT size=4>What is printed to standard output if <TT>fragile()</TT> throws
an IllegalArgumentException?<BR><BR></FONT><INPUT type=checkbox value=CheckBox
name=Q31_a> a) <CODE>"NullPointerException thrown"</CODE><BR><INPUT
type=checkbox value=CheckBox name=Q31_b> b) <CODE>"Exception thrown</CODE><FONT
size=2>"</FONT><BR><INPUT type=checkbox value=CheckBox name=Q31_c> c)
<TT><CODE>"Done with exceptions"</CODE></TT><BR><INPUT type=checkbox
value=CheckBox name=Q31_d> d) <TT><CODE>"myMethod is done"</CODE></TT><BR><INPUT
type=checkbox value=CheckBox name=Q31_e> e) Nothing is printed<FONT
size=4><BR><BR><BR>32. Consider the following code sample:</FONT></P><PRE><CODE>class Tree{}</CODE>
<CODE>class Pine extends Tree{}</CODE>
<CODE>class Oak extends Tree{}</CODE>
<CODE>public class Forest </CODE>
<CODE>{ public static void main( String[] args ) </CODE>
<CODE> { Tree tree = new Pine();</CODE>
<CODE> if( tree instanceof Pine )</CODE>
<CODE> System.out.println( "Pine" );</CODE>
<CODE> if( tree instanceof Tree )</CODE>
<CODE> System.out.println( "Tree" );</CODE>
<CODE> if( tree instanceof Oak )</CODE>
<CODE> System.out.println( "Oak" );</CODE>
<CODE> else System.out.println( "Oops" );</CODE>
<CODE> }</CODE>
<CODE>}</CODE>
</PRE>
<P>Select all choices that will be printed:<BR><BR><INPUT type=checkbox
value=CheckBox name=Q32_a> a) Pine<BR><INPUT type=checkbox value=CheckBox
name=Q32_b> b) Tree<BR><INPUT type=checkbox value=CheckBox name=Q32_c> c)
Forest<BR><INPUT type=checkbox value=CheckBox name=Q32_d> d) Oops<BR><INPUT
type=checkbox value=CheckBox name=Q32_e> e) (nothing printed)<BR><BR><FONT
size=4>33. Consider the classes defined below:</FONT></P><PRE><CODE>import java.io.*;</CODE>
<CODE>class Super </CODE>
<CODE>{</CODE>
<CODE> int methodOne( int a, long b ) throws IOException </CODE>
<CODE> { // code that performs some calculations</CODE>
<CODE> }</CODE>
<CODE> float methodTwo( char a, int b )</CODE>
<CODE> { // code that performs other calculations</CODE>
<CODE> }</CODE>
<CODE>}</CODE>
<CODE>public class Sub extends Super</CODE>
<CODE>{</CODE>
<CODE>}</CODE></PRE>
<P><FONT size=4>Which of the following are legal method declarations to add to
the class <TT>Sub</TT>? Assume that each method is the only one being
added.</FONT></P>
<P><INPUT type=checkbox name=Q33_a><FONT color=black>a) <TT>public static void
main( String args[] ){}</TT><BR></FONT><INPUT type=checkbox name=Q33_b><FONT
color=black>b) <TT>float methodTwo(){}</TT><BR></FONT><INPUT type=checkbox
name=Q33_c><FONT color=black>c) <TT>long methodOne( int c, long d
){}</TT><BR></FONT><INPUT type=checkbox name=Q33_d><FONT color=black>d) <TT>int
methodOne( int c, long d ) throws ArithmeticException{}</TT><BR></FONT><INPUT
type=checkbox name=Q33_e><FONT color=black>e) <TT>int methodOne( int c, long d )
throws FileNotFoundException{}</TT><BR><BR><BR></FONT><FONT size=4>34. Assume
that Sub1 and Sub2 are both subclasses of class Super.<BR><BR>Given the
declarations:<BR></FONT><BR><TT>Super super = new Super();<BR>Sub1 sub1 = new
Sub1();<BR>Sub2 sub2 = new Sub2(); <BR></TT><BR><FONT size=4>Which statement
best describes the result of attempting to compile and execute the following
statement:<BR></FONT><BR><TT>super = sub1;<BR></TT><BR><INPUT type=radio value=a
name=Q34>a) Compiles and definitely legal at runtime<BR><INPUT type=radio
value=b name=Q34>b) Does not compile<BR><INPUT type=radio value=c name=Q34>c)
Compiles and may be illegal at runtime<BR><BR><BR><FONT color=black size=4>35.
For the following code:</FONT></P><PRE><CODE>class Super </CODE>
<CODE>{ int index = 5;</CODE>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -