boolean results[ ] = new boolean [] {true, false, true};
2-
Which three are valid method signatures in an interface?
private int getArea();
public float getVol(float x);
public void main(String [] args);
public static void main(String [] args);
boolean setFlag(Boolean [] test);
A -
1 and 2
B -
2, 3 and 5
C -
3, 4, and 5
D -
2 and 4
3-
What will be the output of the program?
class Super
{
public Integer getLength()
{
return new Integer(4);
}
}
public class Sub extends Super
{
public Long getLength()
{
return new Long(5);
}
public static void main(String[] args)
{
Super sooper = new Super();
Sub sub = new Sub();
System.out.println(
sooper.getLength().toString() + "," + sub.getLength().toString() );
}
}
A -
4, 4
B -
4, 5
C -
5, 4
D -
Compilation fails.
4-
What will be the output of the program?
class Test
{
public static void main(String [] args)
{
int x= 0;
int y= 0;
for (int z = 0; z < 5; z++)
{
if (( ++x > 2 ) && (++y > 2))
{
x++;
}
}
System.out.println(x + " " + y);
}
}
A -
5 2
B -
5 3
C -
6 3
D -
6 4
5-
What will be the output of the program?
int i = l, j = -1;
switch (i)
{
case 0, 1: j = 1; /* Line 4 */
case 2: j = 2;
default: j = 0;
}
System.out.println("j = " + j);
A -
j = -1
B -
j = 0
C -
j = 1
D -
Compilation fails.
6-
What will be the output of the program?
for(int i = 0; i < 3; i++)
{
switch(i)
{
case 0: break;
case 1: System.out.print("one ");
case 2: System.out.print("two ");
case 3: System.out.print("three ");
}
}
System.out.println("done");
A -
done
B -
one two done
C -
one two three done
D -
one two three two three done
7-
What will be the output of the program?
boolean bool = true;
if(bool = false) /* Line 2 */
{
System.out.println("a");
}
else if(bool) /* Line 6 */
{
System.out.println("b");
}
else if(!bool) /* Line 10 */
{
System.out.println("c"); /* Line 12 */
}
else
{
System.out.println("d");
}
A -
a
B -
b
C -
c
D -
d
8-
What will be the output of the program?
class Exc0 extends Exception { }
class Exc1 extends Exc0 { } /* Line 2 */
public class Test
{
public static void main(String args[])
{
try
{
throw new Exc1(); /* Line 9 */
}
catch (Exc0 e0) /* Line 11 */
{
System.out.println("Ex0 caught");
}
catch (Exception e)
{
System.out.println("exception caught");
}
}
}
A -
Ex0 caught
B -
exception caught
C -
Compilation fails because of an error at line 2.
D -
Compilation fails because of an error at line 9.
9-
public class MyProgram
{
public static void throwit()
{
throw new RuntimeException();
}
public static void main(String args[])
{
try
{
System.out.println("Hello world ");
throwit();
System.out.println("Done with try block ");
}
finally
{
System.out.println("Finally executing ");
}
}
}
Ưhich answer most closely indicates the behavior of the program?
A -
The program will not compile.
B -
The program will print Hello world, then will print that a RuntimeException has occurred, then will print Done with try block, and then will print Finally executing.
C -
The program will print Hello world, then will print that a RuntimeException has occurred, and then will print Finally executing.
D -
The program will print Hello world, then will print Finally executing, then will print that a RuntimeException has occurred.
10-
Which interface provides the capability to store objects using a key-value pair?