1.Which will legally declare, construct, and initialize an array?
A.
int [] myList = {"1", "2", "3"};
B.
int [] myList = (5, 8, 2);
C
.
int myList [] [] = {4,9,7,0};
D
.
int myList [] = {4, 3, 7};
2.Which is a reserved word in the Java programming language?
A.
method
B.
native
C
.
subclasses
D
.
reference
E.
array
3.Which is a valid keyword in java?
A.
interface
B.
string
C
.
Float
D
.
unsigned
4.Which is the valid declarations within an interface definition?
A.
public double methoda();
B.
public final double methoda();
C
.
static void methoda(double d1);
D
.
5.
protected void methoda(double d1);
public void foo( boolean a, boolean b)
{
if( a )
{
System.out.println("A"); /*Line5*/
}
else if(a && b) /*Line7*/
{
System.out.println( "A&&B");
}
else /*Line11*/
{
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"
6.
switch(x)
{
default:
System.out.println("Hello");
}
Which two are acceptable types for x?
byte
long
char
float
Short
Long
A
.
1 and 3
B
.
2 and 4
C
.
3 and 5
D
.
4 and 6
7.
public void test(int x)
{
int odd = 1;
if(odd) /*Line4*/
{
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.
8.
public classWhile
{
public void loop()
int x= 0;
while ( 1 ) /*Line6*/
{
System.out.print("xplusoneis" + (x + 1)); /*Line8*/
}
}
}
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.
9.What will be the output of the program?
public classFoo
{
public static void main(String[] args)
{
try
{
return;
}
finally
{
System.out.println( "Finally" );
}
}
}
A
.
Finally
B
.
Compilation fails.
C
.
The code runs with no output.
D
.
An exception is thrown at runtime.
10. What will be the output of the program?
try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
{
System.out.println("Exception");
}
catch (ArithmeticException ae)
{
System.out.println("ArithmeticException");
}
System.out.println("finished");
A
.
finished
B
.
Exception
C
.
Compilation fails.
D
.
Arithmetic Exception
11. What will be the output of the program?
public classX
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod()
{
throw new Error(); /*Line22*/
}
}
A
.
ABCD
B
.
Compilation fails.
C
.
C is printed before exiting with an error message.
D
.
BC is printed before exiting with an error message.
12.What will be the output of the program?
classPassA
{
public static void main(String [] args)
{
PassA p = new PassA();
p.start();
}
void start()
{
long [] a1 = {3,4,5};
long [] a2 = fix(a1);
System.out.print(a1[0] + a1[1] + a1[2] + "");
System.out.println(a2[0] + a2[1] + a2[2]);
}
long [] fix(long [] a3)
{
a3[1] = 7;
return a3;
}
}
A
.
12 15
B
.
15 15
C
.
345375
D
.
375375
13. What will be the output of the program?
classTest
{
public static void main(String [] args)
{
Test p = new Test();
p.start();
}
void start()
{
boolean b1 = false;
boolean b2 = fix(b1);
System.out.println(b1 + "" + b2);
}
boolean fix(boolean b1)
{
b1 = true;
return b1;
}
}
A
.
true true
B
.
false true
C
.
true false
D
.
false false
14. What will be the output of the program?
classPassS
{
public static void main(String [] args)
{
PassS p = new PassS();
p.start();
}
void start()
{
String s1 = "slip";
String s2 = fix(s1);
System.out.println(s1 + "" + s2);
}
String fix(String s1)
{
s1 = s1 + "stream";
System.out.print(s1 + "");
return "stream";
}
}
A
.
slip stream
B
.
slipstream stream
C
.
stream slip stream
D
.
slipstream slip stream