Professional Documents
Culture Documents
SCJP 1
SCJP 1
The class AssertionError has "is - a" relationship with these classes:
RuntimeException
Error
VirtualMachineError
IllegalAccessException
Throwable
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