1-
|
import java.awt.*;
class Ticker extends Component
{
public static void main (String [] args)
{
Ticker t = new Ticker();
/* Missing Statements ? */
}
}
which two of the following statements, inserted independently, could legally be inserted into missing section of this code?
- boolean test = (Component instanceof t);
- boolean test = (t instanceof Ticker);
- boolean test = t.instanceof(Ticker);
- boolean test = (t instanceof Component);
|
|
A -
|
1 and 4
|
|
B -
|
2 and 3
|
|
C -
|
1 and 3
|
|
D -
|
2 and 4
|
2-
|
Which of the following are legal lines of code?
- int w = (int)888.8;
- byte x = (byte)1000L;
- long y = (byte)100;
- byte z = (byte)100L;
|
|
A -
|
1 and 2
|
|
B -
|
2 and 3
|
|
C -
|
3 and 4
|
|
D -
|
All statements are correct.
|
3-
|
Which two statements are equivalent?
- 16*4
- 16>>2
- 16/2^2
- 16>>>2
|
|
A -
|
1 and 2
|
|
B -
|
2 and 4
|
|
C -
|
3 and 4
|
|
D -
|
1 and 3
|
4-
|
Which two statements are equivalent?
- 3/2
- 3<2
- 3*4
- 3<<2
|
|
A -
|
1 and 2
|
|
B -
|
2 and 3
|
|
C -
|
3 and 4
|
|
D -
|
1 and 4
|
5-
|
import java.awt.Button;
class CompareReference
{
public static void main(String [] args)
{
float f = 42.0f;
float [] f1 = new float[2];
float [] f2 = new float[2];
float [] f3 = f1;
long x = 42;
f1[0] = 42.0f;
}
}
which three statements are true?
- f1 == f2
- f1 == f3
- f2 == f1[1]
- x == f1[0]
- f == f1[0]
|
|
A -
|
1, 2 and 3
|
|
B -
|
2, 4 and 5
|
|
C -
|
3, 4 and 5
|
|
D -
|
1, 4 and 5
|
6-
|
Which two are equal?
- 32/4
- (8 >> 2) << 4
- 2^5
- 128 >>> 2
- 2 >> 5
|
|
A -
|
1 and 2
|
|
B -
|
2 and 4
|
|
C -
|
1 and 3
|
|
D -
|
2 and 3
|
7-
|
public void foo( boolean a, boolean b)
{
if( a )
{
System.out.println("A"); /* Line 5 */
}
else if(a && b) /* Line 7 */
{
System.out.println( "A && B");
}
else /* Line 11 */
{
if ( !b )
{
System.out.println( "notB") ;
}
else
{
System.out.println( "ELSE" ) ;
}
}
}
|
|
A -
|
If a is true and b is true then the output is "A && B"
|
|
B -
|
If a is true and b is false then the output is "notB"
|
|
C -
|
If a is false and b is true then the output is "ELSE"
|
|
D -
|
If a is false and b is false then the output is "ELSE"
|
8-
|
switch(x)
{
default:
System.out.println("Hello");
}
Which two are acceptable types for x?
|
|
A -
|
1 and 3
|
|
B -
|
2 and 4
|
|
C -
|
3 and 5
|
|
D -
|
4 and 6
|
9-
|
public void test(int x)
{
int odd = 1;
if(odd) /* Line 4 */
{
System.out.println("odd");
}
else
{
System.out.println("even");
}
}
Which statement is true?
|
|
A -
|
Compilation fails.
|
|
B -
|
"odd" will always be output.
|
|
C -
|
"even" will always be output.
|
|
D -
|
"odd" will be output for odd values of x, and "even" for even values.
|
10-
|
public class While
{
public void loop()
{
int x= 0;
while ( 1 ) /* Line 6 */
{
System.out.print("x plus one is " + (x + 1)); /* Line 8 */
}
}
}
Which statement is true?
|
|
A -
|
There is a syntax error on line 1.
|
|
B -
|
There are syntax errors on lines 1 and 6.
|
|
C -
|
There are syntax errors on lines 1, 6, and 8.
|
|
D -
|
There is a syntax error on line 6.
|