You are on page 1of 4

1.

The class AssertionError has "is - a" relationship with these classes:
RuntimeException
Error
VirtualMachineError
IllegalAccessException
Throwable

2. What will be the result of executing the following code?


1. boolean a = true;
2. boolean b = false;
3. boolean c = true;
4. if (a == true)
5. if (b == true)
6. if (c == true) System.out.println("Some things are true in this world");
7. else System.out.println("Nothing is true in this world!");
8. else if (a && (b = c)) System.out.println("It's too confusing to tell what is true and
what is false");
9. else System.out.println("Hey this won't compile");

a) The code won't compile


b) "Some things are true in this world" will be printed
c) "Hey this won't compile" will be printed
d) None of these

3. What will happen when you attempt to compile and run the following code?
interface MyInterface
{
}
public class MyInstanceTest implements MyInterface
{
static String s;
public static void main(String args[])
{
MyInstanceTest t = new MyInstanceTest();
if(t instanceof MyInterface)
{
System.out.println("I am true interface");
}
else
{
System.out.println("I am false interface");
}
if(s instanceof String)
{
System.out.println("I am true String");
}
else
{
System.out.println("I am false String");
}
}
}
a) Compile time error
b) Runtime error
c) Prints : "I am true interface" followed by " I am true String"
d) Prints : "I am false interface" followed by " I am false String"
e) Prints : "I am true interface" followed by " I am false String"
f) Prints : "I am false interface" followed by " I am true String"
4. What results from attempting to compile and run the following code?
public class Ternary
{
public static void main(String args[])
{
int a = 5;
System.out.println("Value is - " + ((a < 5) ? 9.9 : 9));
}
}
a) Prints: Value is - 9
b) Prints: Value is - 5
c) Compilation error
d) None of these

5. In the following pieces of code, A and D will compile without any error. True/False?
A: StringBuffer sb1 = "abcd";
B: Boolean b = new Boolean("abcd");
C: byte b = 255;
D: int x = 0x1234;
E: float fl = 1.2;
a) True
b) False

6. Considering the following code, which variables may be referenced correctly at line 12?
public class Outer
{
public int a = 1;
private int b = 2;
public void method(final int c)
{
int d = 3;
class Inner
{
private void iMethod(int e)
{
}
}
}
}

a) a
b) b
c) c
d) d
e) e

You might also like