Q1.
public class InitTest {
public static int VALUE = 100;
static
{
System.out.println("VALUE1 = " + VALUE);
VALUE += 200;
System.out.println("VALUE2 = " + VALUE);
}
public InitTest() {
System.out.println("VALUE3 = " + VALUE);
VALUE += 300;
System.out.println("VALUE4 = " + VALUE);
}
public static void main(String args[]) {
new InitTest();
new InitTest();
}
}
Output:
Q2.
public class InitTest {
public static int VALUE = 100;
static
{
System.out.println("VALUE1 = " + VALUE);
VALUE += 200;
System.out.println("VALUE2 = " + VALUE);
}
public InitTest() {
System.out.println("VALUE3 = " + VALUE);
VALUE += 300;
System.out.println("VALUE4 = " + VALUE);
}
public static void main(String args[]) {
new InitTest();
new InitTest();
}
}
Output:
Q3.
String a = "abc";
String b = new String("abc");
String c = "abc";
System.out.println(a==b);
System.out.println(a==c);
System.out.println(a.equals(b));
Output:
Q4.
String a=null;
if (a!=null && a.length()>10) {
System.out.println("pass");
}
Output:
Q5.
String a=null;
if (a!=null & a.length()>10) {
System.out.println("pass");
}
Output:
Q6.
int i = -1;
System.out.println(i>>31);
i = -1;
System.out.println(i>>>31);
output:
Q7.
try {
System.out.println("Pass 1");
System.exit(0);
System.out.println("Pass 2");
}finally {
System.out.println("Pass 3");
}
Output:
Q8.
try {
System.out.println("Pass 1");
return;
System.out.println("Pass 2");
}finally {
System.out.println("Pass 3");
}
Output:
Q9.
byte a = 100;
a = a + 20;
System.out.println(a);
Output:
Q10.
try {
RandomAccessFile raf = new RandomAccessFile("c:\\file.txt", "r");
System.out.println("Open");
raf.read();
System.out.println("Read");
} catch (IOException ex) {
ex.printStackTrace();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
System.out.println("Finally");
}
Output:
Answer: http://dbblogger.blog.com/2012/07/13/java-quiz/