class SC2
{
public static void main(String [] args)
{
SC2 s = new SC2();
s.start();
}
void start()
{
int a = 3;
int b = 4;
System.out.print(" " + 7 + 2 + " ");
System.out.print(a + b);
System.out.print(" " + a + b + " ");
System.out.print(foo() + a + b + " ");
System.out.println(a + b + foo());
}
String foo()
{
return "foo";
}
}
A -
9 7 7 foo 7 7foo
B -
72 7 34 foo34 7foo
C -
9 7 7 foo34 34foo
D -
72 34 34 foo34 34foo
2-
What will be the output of the program?
class BoolArray
{
boolean [] b = new boolean[3];
int count = 0;
void set(boolean [] x, int i)
{
x[i] = true;
++count;
}
public static void main(String [] args)
{
BoolArray ba = new BoolArray();
ba.set(ba.b, 0);
ba.set(ba.b, 2);
ba.test();
}
void test()
{
if ( b[0] && b[1] | b[2] )
count++;
if ( b[1] && b[(++count - 2)] )
count += 7;
System.out.println("count = " + count);
}
}
A -
count = 0
B -
count = 2
C -
count = 3
D -
count = 4
3-
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
4-
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 false and b is true then the output is "ELSE"
C -
If a is true and b is false then the output is "notB"
D -
If a is false and b is false then the output is "ELSE"
5-
What will be the output of the program?
Float f = new Float("12");
switch (f)
{
case 12: System.out.println("Twelve");
case 0: System.out.println("Zero");
default: System.out.println("Default");
}
A -
Zero
B -
Twelve
C -
Default
D -
Compilation fails
6-
What will be the output of the program?
public class Test
{
public static void aMethod() throws Exception
{
try /* Line 5 */
{
throw new Exception(); /* Line 7 */
}
finally /* Line 9 */
{
System.out.print("finally "); /* Line 11 */
}
}
public static void main(String args[])
{
try
{
aMethod();
}
catch (Exception e) /* Line 20 */
{
System.out.print("exception ");
}
System.out.print("finished"); /* Line 24 */
}
}
A -
Finally exception finished
B -
Exception finished
C -
Compilation fails
D -
Finally
7-
Which statement is true for the class java.util.ArrayList?
A -
The elements in the collection are ordered.
B -
The collection is guaranteed to be immutable.
C -
The elements in the collection are guaranteed to be unique.
D -
The elements in the collection are accessed using a unique key.
8-
What will be the output of the program?
class A
{
final public int GetResult(int a, int b) { return 0; }
}
class B extends A
{
public int GetResult(int a, int b) {return 1; }
}
public class Test
{
public static void main(String args[])
{
B b = new B();
System.out.println("x = " + b.GetResult(0, 1));
}
}
A -
x = 0
B -
x = 1
C -
Compilation fails.
D -
An exception is thrown at runtime.
9-
Which is true about a method-local inner class?
A -
It must be marked final.
B -
It can be marked abstract.
C -
It can be marked public.
D -
It can be marked static.
10-
class X implements Runnable
{
public static void main(String args[])
{
/* Missing code? */
}
public void run() {}
}
Which of the following line of code is suitable to start a thread ?
A -
Thread t = new Thread(X);
B -
Thread t = new Thread(X); t.start();
C -
X run = new X(); Thread t = new Thread(run); t.start();