Q1.What will be the result of compiling and running the given program?
Select one correct answer.
1. public class Q1
2. {
3. public static void main(String[] args)
4. {
5. boolean t1 = true, t2 = false, t3 = t1;
6. boolean t = false;
7. t &&= (t1 || ( t2 && t3));
8. System.out.println("boolean t = "+t);
9. }
10.}
Q2.What will be the result of compiling and running the given program?
Select one correct answer.
1. public class Q2
2. {
3. public static void main(String[] args)
4. {
5. int[] a;
6. a = new int[0];
7. call(a);
8. System.out.println(a.length+" , "+a[0]);
9. }
10. static void call(int[] a)
11. {
12. int[] b = {4,5,6};
13. a = b;
14. a = new int[6];
15. }
16. }
Q3.Which of the given choices are true?Select any two.
1. public class Q3
2. {
3. public static void main(String[] args)
4. {
5. long l = 2;
6. int l1 = 2;
7. long i = l1 >> 33;
8. int i1 = l1 >> 33;
9. long i2 = l >> 33;
10. if ( i = = i2)
11. System.out.println("equal");
12. else
13. System.out.println("not equal");
14.
15. if ( i = = i1)
16. System.out.println("equal");
17. else
18. System.out.println("not equal");
19. }
20. }
Q4.What will be the result of compiling and running the given program?
Select one correct answer.
1. public class Q4
2. {
3. public static void main(String[] args)
4. {
5. double d = Integer.MAX_VALUE;
6. float f= Integer.MAX_VALUE;
7. if (f == d)
8. System.out.println("equal");
9. else
10. System.out.println(" not equal ");
11. }
12. }
Q5.What will be the result of compiling and running the given program?Select any two.
1. public class Q5
2. {
3. public static void main(String[] args)
4. {
5. int a[] = {4,5,9,8,6,6,0};
6. int i=1;
7. a[i] = i+= a[i++];
8. System.out.println(a[i]);
9. System.out.println(i);
10. }
11. }
Q6.What will be the result of compiling and running the given program?
Select one correct answer.
1. public class Q6
2. {
3. public static void main(String[] args)
4. {
5. int a=1,b=2,c=3;
6. a=b=c;
7. boolean bool;
8. bool = a = = b = = c;
9. System.out.println(a+b+c+" , "+bool);
10. }
11. }
Q7.What will be the result of compiling and running the given program?
Select one correct answer.
1. public class Q7
2. {
3. public static void main(String[] args)
4. {
5. int i=5;
6. System.out.println(i%-0.0);
7. }
8. }
Q8.Which of the following are not legal declarations in a class?.
Select two correct answers.
Q9.Which one of the following are valid declaration of switch statements?Select any two.
Q10.What will be the result of compiling and running the given program?
Select one correct answer. 1. public class Q10
2. {
3. public static void main(String[] args)
4. {
5. int i=3;
6. System.out.println(i*=2 + i++);
7. }
8. }
Q11.What will be the result of compiling and running the given program?
Select one correct answer.
1. public class Q11
2. {
3. static int i=4;
4. Q11()
5. {
6. i=i++;
7. }
8. void Q11()
9. {
10. this();
11. System.out.println(i);
12. }
13. public static void main(String args)
14. {
15. Q11 q1 = new Q11();
16. q1.Q11();
17. }
18. }
Q12.What will be the result of compiling and running the given program?
Select one correct answer.
1. public class Q12
2. {
3. public static void main(String[] args)
4. {
5. char x='1';
6. switch (x)
7. {
8. default:
9. System.out.println("default");
10. case 1:
11. System.out.println("case 1");
12. case 2:
13. System.out.println("case 2");
14. break;
15. }
16. }
17. }
Q13.What will be the result of compiling and running the given program?
Select one correct answer.
1. public class Q13
2. {
3. static int call(int x)
4. {
5. try
6. {
7. System.out.println(x---x/0);
8. return x--;
9. }
10. catch(Exception e)
11. {
12. System.out.println(--x-x%0);
13. return x--;
14. }
15. finally
16. {
17. return x--;
18. }
19. }
20. public static void main(String[] args)
21. {
22. System.out.println(" value = "+ call(5));
23. }
24. }
Q14.What will be the result of compiling and running the given program?
Select one correct answer.
1. public class Q14
2. {
3. public static void main(String[] args)throws Exception
4. {
5. RuntimeException re = null;
6. try
7. {
8. throw re;
9. }
10. catch(Exception e)
11. {
12. throw e;
13. }
14. finally
15. {
16. throw re;
17. }
18. }
19. }
Q15.What will happen if I save,compile and run the bellow code as Q15.java?
Select one correct answer.
1. class superclass
2. {
3. public static void main(String[] args)
4. {
5. System.out.println("Hello");
6. }
7. }
8. class Q15 extends superclass
9. {
10. }
Q16.What will be the result of compiling and running the given program?
Select one correct answer.
1. interface I1 {}
2. interface I2 {}
3. class A implements I2{}
4. class Q16 extends A implements I1
5. {
6. public static void main(String[] args)
7. {
8. A a = new Q16();
9. I2 i2 = a;
10. I1 i1 = (I1)a;
11. }
12. }
Q17.What will be the result of compiling and running the given program?
Select one correct answer.
1. interface I1 {}
2. interface I2 extends I1{}
3. class A implements I2{}
4. class Q17 implements I2 extends A
5. {
6. public static void main(String[] args)
7. {
8. Q17 q =new Q17();
9. I1 i1 = q;
10. }
11. }
Q18.What will be the result of compiling and running the given program?
Select one correct answer.
1. class superclass
2. {
3. void method1(int i){}
4. void method2(final int j){}
5. void method3(){}
6. }
7. class Q18 extends superclass implements Runnable
8. {
9. void method1(final int i){}
10. void method2(int j) throws ArithmeticException{}
11. void method3() throws InterruptedException{}
12. synchronized void run() throws NullPointerException{}
13. }
Q19.What will be the result of compiling and running the given program?
Select one correct answer.
1. class Q19
2. {
3. private static int increase(int i)
4. {
5. return i++;
6. }
7. public Q19()
8. {
9. i = increase(1);
10. }
11. {
12. i = increase(1);
13. }
14. static int i = increase(1);
15. public static void main(String[] args)
16. {
17. System.out.println(i=increase(i));
18. }
19. }
Q20.Which of the given choices can make the program compiles and run without any error?
Select any two.
1. interface I1 {}
2. class A {}
3. class Q20 extends A implements I1
4. {
5. public static void main(String[] args)
6. {
7. Q20 q = new Q20();
8. A a =new A();
9. I1 i1 = (I1)a; //This line is giving ClassCastException.
10. }
11. }
Q21.What will be the result of compiling and running the given program?
Select one correct answer.
1. interface I1 {}
2. class A {}
3. class Q21 extends A implements I1
4. {
5. public static void main(String[] args)
6. {
7. Q21 q = new Q21();
8. A a =null;
9. I1 i1 = (I1)a;
10. }
11. }
Q22.Which method is used to make the thread eligible for running?
Select one correct answer.
Q23.What is the default priority of a thread?Select one correct answer.
Q24.What will be the result of compiling and running the given program?
Select one correct answer.
1. class Q24
2. {
3. public static void main(String[] args)
4. {
5. StringBuffer str =new StringBuffer("Hello");
6. String str1 = new String(str);
7. if (str.equals(str1))
8. System.out.println("true");
9. else
10. System.out.println("false");
11. }
12.}
Q25.What will be the result of compiling and running the given program?
Select one correct answer.
1. class Q25
2. {
3. public static void main(String[] args)
4. {
5. Boolean bool1 = new Boolean("Wrong");
6. Boolean bool2 = new Boolean("True");
7. System.out.println(bool1.toString());
8. System.out.println(bool2.toString());
9. }
10.}
Q26.What will be the value of st after line no.14?Enter your answer in the given field.
Don't use any extra signs like ("")quotes or any string like "st=".For example,
if your answer is the string "XYZ" you just write XYZ
1. class Q26
2. {
3. public static void main(String[] args)
4. {
5. String str = new String("Hello"),st="";
6. if (str.substring(0) == str)
7. st+="A";
8. else
9. st+="B";
10. if (str.replace('k','j') == str)
11. st+="C";
12. else
13. st+="D";
14. System.out.println(st);
15. }
16. }
Q27.Which of the following regarding garbage collection are true?
Select any two.
Q28.What will be the result of compiling and running the given program?
Select one correct answer.1. class Q28
2. {
3. public static void main(String[] args)
4. {
5. System.out.println(Math.ceil(-0.5)+"/"+Math.floor(-0.5));
6. }
7. }
Q29.Which of the following collection implementations are thread safe?
Select any two.
Q30.What is the default number of rows visible in a List?
Select one correct answer.
Q31.Which interface is implemented by the MouseMotionAdapter class?
Select one correct answer.
Q32.What will be the result of compiling and running the given program?
Select one correct answer.
1. class Q32
2. {
3. public static void main(String[] args)
4. {
5. Frame f = new Frame("My frame");
6. f.setLayout(new GridBagLayout());
7. GridBagConstraints gbc = new GridBagConstraints();
8. f.add(new Button("B1"));
9. f.add(new Button("B2"));
10. f.setSize(400,400);
11. f.setVisible(true);
12. }
13. }
Q33.Name the component whose prefered size is honoured by BorderLayout?
Select one correct answer.
Q34.Which of the following are valid constructors of IO stream classes?
Select one correct answer.
Q35.Which of the following are valid constructors of IO classes?
Select one correct answer.
Q36.What will be the result of compiling and running the given program?
Select one correct answer. 1. class Q36 extends Thread
2. {
3. public void run()
4. {
5. System.out.println("Hello");
6. }
7. public static void main(String[] args)
8. {
9. Runnable r = new Q36();
10. Thread t = new Thread(r);
11. t.run();
12. }
13. }
Q37.What will be the result of compiling and running the given program?
Select one correct answer. 1. class Q37
2. {
3. public static void main(String[] args)
4. {
5. String s1 = null;
6. String s2 = null;
7. if (s1 == s2)
8. System.out.print("A");
9. else
10. System.out.print("B");
11. if (s1 .equals(s2))
12. System.out.print("C");
13. else
14. System.out.print("D");
15. }
16. }
Q38.Which of the following about inner classes are true?Select any two.
Q39.What will be the result of compiling and running the given program?
Select one correct answer. 1. public class Q39
2. {
3. public static void main(String args[])
4. {
5. int x = 10;
6. final int y;
7. if(x++ > 10)
8. y = 1;
9. else
10. y = 2;
11. System.out.println("y is " + y);
12. }
13. }
Q40.Which of the following are methods of ComponentListener?Select any two.
Q41.Whether the following code compile or not?
Select the most appropriate one answer.
1. class Q41
2. {
3. public static void main(String arg[])
4. {
5. final int y;
6. }
7. }
Q42.What will be the result of compiling and running the given program?
Select one correct answer.
1. class Q42
2. {
3. public static void main(String args[])
4. {
5. int b='A';
6. System.out.write(b);
7. }
8. }
Q43.What will be the result of compiling and running the given program?
Select one correct answer. 1. class Q43
2. {
3. int y=1;
4. Q43()
5. {
6. this(y);
7. }
8. Q43(int x)
9. {
10. y=x++ + ++x;
11. }
12. public static void main(String [] args)
13. {
14. Q43 t = new Q43();
15. System.out.println(t.y);
16. }
17. }
Q44.What will be the result of compiling and running the given program?
Select one correct answer. 1. class Q44
2. {
3. public static void main(String[] args)
4. {
5. int intNumber = 123456789;
6. float floatNumber = intNumber;
7. int x = (int)floatNumber;
8. System.out.println(intNumber - x);
9. System.out.println(intNumber == x );
10. }
11. }
Q45.What will be the result of compiling and running the given program?
Select one correct answer. 1. public class Q45
2. {
4. static
5. {
6. System.out.print("Java".startsWith(""));
7. }
8. static void processorB()
9. {
10. System.out.println(" is a boolean Operator.");
11. }
12. static Q45 processorA()
13. {
14. Q45 q=null;
15. if (("java").startsWith("null"))
16. return q;
17. else
18. return null;
19. }
20. public static void main(String[] args)
21. {
22. processorA().processorB();
23. }
24. }
Q46.What will be the result of compiling and running the given program?
Select one correct answer.
1. class Q46
2. {
3. public static void main(String [] args)
4. {
5. String str = "Java";
6. str += "Beans";
7. if(str.equals("JavaBeans"))
8. System.out.println("TRUE" );
9. else
10. System.out.println("FALSE" );
11. if(str == "JavaBeans")
12. System.out.println("TRUE" );
13. else
14. System.out.println("FALSE" );
15. }
16. }
Q47.Which of the following is not valid adapter class?Select one correct answer.
Q48.What will be the result of compiling and running the given program?
Select one correct answer. 1. class Except extends Exception{}
2. public class Q48
3. {
4. public static void main(String[]args)
5. {
6. try
7. {
8. System.out.println(10/0);
9. }
10. catch(Except e)
11. {
12. System.out.println("catch block");
13. }
14. }
15.}
Q49.Which of these are legal ways of accessing a File named "file.txt" for
writing.Select one correct answer.
Q50.What will be the result of compiling and running the given program?
Select one correct answer.
1. public class Q50
2. {
3. public static void main(String argv[])
4. {
5. int x=31;
6. System.out.println( x >>> 1 + x);
7. System.out.println( -x >>> 1 + x);
7. }
8. }
Q51.What is the name of collection interface used to maintain unique elements
in order?Select one correct answer.
Q52.What is the name of interface used to store data as key-value pairs?
Select one correct answer.
Q53.What will be the result of compiling and running the given program?
Select one correct answer. 1. class Q53
2. {
3. public static void main(String [] args)
4. {
5. java.lang.StringBuffer sb;
6. sb = new java.lang.StringBuffer().append("Hello").append("World");
7. System.out.println(sb. substring(5,10).toString());
8. }
9. }
Q54.Which of the following methods can force a thread to leave the Lock(monitor)?
Select any two.
Q55.What will be the result of compiling and running the given program?
Select one correct answer. 1. class Q55
2. {
3. public static void main(String[] args)
4. {
5. int[] a={11,12,13,14};
6. int[] b={0,1,2,3};
7. System.out.println(a[(a=b)[3]]);
8. }
9. }
Q56.What will be the result of compiling and running the given program?
Select one correct answer.
1. public class Q56
2. {
3. static boolean x;
4. public static void main(String args[])
5. {
6. int a;
7. if(x)
8. a = x ? 1: 2;
9. else
10. a = x ? 3: 4;
11. System.out.println(a);
12. }
13. }
Q57.What will be the result of compiling and running the given program?
Select one correct answer.
1. class Q57
2. {
3. public static double[] d ;
4. public static void main(String [] args)
5. {
6. Q57 x = new Q57();
7. x.methodA(d);
8. }
9. void methodA(double[] d1)
10. {
11. System.out.println(d1[0]);
12. }
13. }
Q58.Which of the following statement is true?Select one correct answer.
1. class Q58
2. {
3. int x=0;
4. final int y=0;
5. private int z=0;
6. void xyz()
7. {
8. int a=0;
9. final int b=0;
10. class abcd
11. {
12. abcd()
13. {
14. System.out.println(x);
15. System.out.println(b);
16. System.out.println(a);
17. System.out.println(y);
18. System.out.println(z);
19. }
20. }
21. }
22. }
Q59.Which of the following statement can be placed at line number 8, without
causing any error?Select one correct answer.
1. public class OuterTest
2. {
3. class Inner
4. {
5. }
6. public static void main(String args[])
7. {
8. //Here
9. }
10.}