Q1.What will be the result of compiling and running the given program?
Select one correct answer.
1 class Q1
2 {
3 public static void main(String arg[])
4 {
5 int a[]={2,2};
6 int b=1;
7 a[b]=b=0;
8 System.out.println(a[0]);
9 System.out.println(a[1]);
10 }
11 }
Q2.What will be the result of compiling and running the given program?
Select one correct answer.
1 class Q2
2 {
3 public static void main(String arg[])
4 {
5 StringBuffer s[]={"A","B"};
6 System.out.println(s[0]+","+s[1]);
7 }
8 }
Q3.Which of the given choices are true?Select any two.
1 class Q3
2 {
3 public static void main(String arg[])
4 {
5 int[] a,c,d[];
6 int b[]=new int[0];
7 }
8 }
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 boolean t1 = true, t2 = false, t3 = t1;
6 boolean t = false;
7 t &&= (t1 || ( t2 && t3));
8 System.out.println(t);
9 }
10 }
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 rag[])
4 {
5 byte b=1;
6 b++;
7 byte b=127+1;
8 int i=2147483647+1;
9 b=- -b;
10 }
11 }
Q6.What will be the result of compiling and running the given program?
Select one correct answer.
1 class AA{}
2 class BB extends AA{}
3 class Q6
4 {
5 public static void main(String arg[])
6 {
7 AA a=null;
8 BB b=(BB)a;
9 System.out.println(b);
10 System.out.println(b instanceof BB);
11 System.out.println(b instanceof AA);
12 }
13 }
Q7.Which one of the following statements will give you an Exception when
placed at line no.10?Select one correct answer.
1 class AA{}
2 class BB extends AA{}
3 class casting
4 {
5 public static void main(String arg[])
6 {
7 AA a=new AA();
8 BB b=new BB();
9 AA c=new BB();
10 //Here
11 }
11 }
Q8.Which one of the following are valid character contants?Select any two.
Q9.Which one of the following are not valid character contants?Select any two.
Q10.Which will be the first line to cause an error in the following code?
Select one correct answer.
1 class Char
2 {
3 public static void main(String arg[])
4 {
5 char c1,c2;
6 c1='A';
7 c1++;
8 c1+=1;
9 c1=c1+1;
10 c2='B';
11 c2--;
12 c2=c2-1;
13 }
14 }
Q11.What will be the result of compiling and running the given program?
Select one correct answer.
1 public class Child extends Parent
2 {
3 public static int test(int i)
4 {
5 return 20;
6 }
7 public static void main(String[] args)
8 {
9 Parent c = new Child();
10 System.out.println(c.test(10));
11 }
12 }
13 class Parent
14 {
15 public static int test(int i)
16 {
17 return 5;
18 }
19 }
Q12.What will be the result of compiling and running the given program?
Select one correct answer.
1 public class Q12
2 {
3 String str;
4 public static void main(String[] args)
5 {
6 Q12 a = new Q12();
7 a.append("B");
8 a.append("C");
9 System.out.println(a.str);
10 }
11 void append(String s)
12 {
13 str+=s;
14 }
15 }
Q13.What will be the result of compiling and running the given program?
Select one correct answer.
1 class sample
2 {
3 sample(String s)
4 {
5 System.out.println("String");
6 }
7 sample(Object o)
8 {
9 System.out.println("Object");
10 }
11 }
12 class constructor
13 {
14 public static void main(String arg[])
15 {
16 sample s1=new sample(null);
17 }
18 }
Q14.What will be the result of compiling and running the given program?
Select one correct answer.
1 class sample
2 {
3 sample(String s)
4 {
5 System.out.println("String");
6 }
7 sample(StringBuffer sb)
8 {
9 System.out.println("StringBuffer");
10 }
11 }
12 class constructor
13 {
14 public static void main(String arg[])
15 {
16 sample s1=new sample(null);
17 }
18 }
Q15.Which one of the following method will return closest integer but not less than
for any value passed as argument d?Select one correct answer.
Q16.What will be the result of compiling and running the given program?
Select one correct answer.
1 class A
2 {
3 void callme()
4 {
5 System.out.println("A");
6 }
7 int r=10;
8 }
9 class B extends A
10 {
11 public void callme()
12 {
13 System.out.println("B");
14 }
15 int r=20;
16 }
17 class Q16
18 {
19 public static void main(String args[])
20 {
21 A a = new B();
22 a.callme();
23 System.out.println(a.r);
24 }
25 }
Q17.Which one of the following methods will give you an error when placed at
line no.10?Select one correct answer.
1 class A
2 {
3 public void callme()
4 {
5 System.out.println("A");
6 }
7 }
8 class B extends A
9 {
10 //Here
11 }
Q18.Which will be the first line to cause an error in the following code?
Select one correct answer.
1 class Char
2 {
3 public static void main(String arg[])
4 {
5 while(false)
6 {
7 System.out.println("Hello");
8 }
9 while(false)
10 {
11 }
12 do;
13 while(false);
14 do
15 {
16 ;
17 }
18 while(false);
19 }
20 }
Q19.Which of the given choices is true?Select one correct answer.
1 class equal
2 {
3 public static void main (String args[])
4 {
5 StringBuffer sb1 = new StringBuffer("Amit");
6 StringBuffer sb2= new StringBuffer("Amit");
7 String ss1 = "Amit";
8 System.out.println(sb1==sb2);
9 System.out.println(sb1.equals(sb2));
10 System.out.println(sb1.equals(ss1));
11 System.out.println(sb1==ss1);
12 }
13 }
Q20.Which of the given choices are true?Select any two.
Q25.Whether the following code compile or not?
Select the most appropriate answer.
1 public class Q25
2 {
3 final static int fsn;
4 final int fn;
5 static
6 {
7 fsn=6;
8 }
9 {
10 fn =8;
11 }
12 }
Q26.What will be the value of str after line no.7?Enter your answer in the given field.
Don't use any extra signs like ("")quotes or any string like "str=".For example,
if your answer is the string "XYZ" you just write XYZ
Q27.What will be the result of compiling and running the given program?
Select any two.
1 import java.util.*;
2 import java.sql.*;
3 class Q27
4 {
5 Date d;
6 public static void main(String arg[])
7 {
8 }
6 }
Q28.Which one of the following is the simplest way to print the value of variable
text at line no. 18?Select one correct answer.
1 class Message
2 {
3 String text="Hello1";
4 }
5 class Super
6 {
7 Message msg=new Message();
8 }
9 class inheritance extends Super
10 {
11 public static void main(String arg[])
12 {
13 inheritance i=new inheritance();
14 i.print();
15 }
16 public void print()
17 {
18 //Here
19 }
20 }
Q29.Whether the following code compile or not?
Select any two.
1 class Base {}
2 class Agg extends Base
3 {
4 public String getFields()
5 {
6 String name = "Agg";
7 return name;
8 }
9 }
10 public class Inheritence
11 {
12 public static void main(String argv[])
13 {
14 Base a = new Agg();
15 System.out.println(a.getFields());
16 }
17 }
Q30.What will be the result of compiling and running the given program?
Select one correct answer.
1 class Q30
2 {
3 static int p=abc();
4 static public int abc()
5 {
6 int i=123;
7 System.out.println(p);
8 return i;
9 }
10 public static void main(String arg[])
11 {
12 }
13 }
Q31.What will be the result of compiling and running the given program?
Select one correct answer.
1 public class initialize
2 {
3 public initialize(int m)
4 {
5 System.out.println(i+","+j+","+k+","+x+","+m);
6 }
7 public static void main(String[]args)
8 {
9 initialize obj=new initialize(x);
10 }
11 static int i=5;
12 static int x;
13 int j=7;
14 int k;
15 {
16 j=70;x=20;
17 }
18 static
19 {
20 i=50;
21 }
22 }
Q32.What will be the result of compiling and running the given program?
Select one correct answer.
Q33.Which will be the first line to cause an error in the following code?
Select one correct answer.
1 class Outer
2 {
3 class Inner
4 {
5 final int a=20;
6 static final int b=20;
7 static int c=20;
8 }
9 }
Q34.Which of the following will be the correct way to make the object of class one
at line no.11?Select one correct answer.
1 class outer
2 {
3 class one
4 {
5 }
6 }
7 class Q33
8 {
9 public static void main(String a[])
10 {
11 //Here
12 }
13 }
Q35.What will be the result of compiling and running the given program?
Select one correct answer.
1 class instanceOf
2 {
3 public static void main(String arg[])
4 {
5 G g=new G();
6 H h=new H();
7 System.out.println(h instanceof G);
8 }
9 }
10 class G{}
11 class H{}
Q36.Which of the following method will not give you any error when placed on
line no.3?Select one correct answer.
1 interface i2
2 {
3 //Here
4 }
Q37.Which of the following statement will not give you any error when placed
on line no.3?Select one correct answer.
1 interface i2
2 {
3 //Here
4 }
Q38.Which two of the following statement will give you same results?Select any two.
Q39.Which of the following variable is not accessible at line no.12?
Select one correct answer.
1 class outer
2 {
3 private int a=0;
4 int b=0;
5 static int c=0;
6 public void xyz(int d)
7 {
8 final int e=0;
9 class local
10 {
11 {
12 //Here
13 }
14 }
15 }
16 }
Q40.Which two of the following are valid declaration for main() method?
Select any two.
Q41.What will be the result of compiling and running the given program?
Select one correct answer.
1 class Q41
2 {
3 public static void main(String arg[])
4 {
5 System.out.println(Math.abs(-2147483648);
6 }
7 }
Q42.What will be the result of compiling and running the given program?
Select one correct answer.
Q43.After which line the object initially refered by str is eligible for garbage
collection?Select one correct answer.
1 class Garbage
2 {
3 public static void main(String arg[])
4 {
5 String str=new String("Hello");
6 String str1=str;
7 str=new String("Hi");
8 str1=new String("Hello Again");
9 return;
10 }
11 }
Q44.Which of the following classes is not derived from the Component class.
Select one correct answer.
Q45.Name the method defined in EventObject class that returns the Object generated
from the event.Select the one correct answer.
Q46.Which of the following is not valid event class?Select one correct answer.
Q47.Which of the following is valid adapter class?Select one correct answer.
Q48.How will the following program lay out its buttons.
Select one correct answer.
1 import java.awt.*;
2 public class MyClass
3 {
4 public static void main(String args[])
5 {
6 String[] labels = {"A"};
7 Window win = new Frame();
8 win.setLayout(new FlowLayout());
9 for(int i=0;i < labels.length;i++)
10 win.add(new Button(labels[i]));
11 win.pack();
12 win.setVisible(true);
13 }
14 }
Q49.Which of these are legal ways of accessing a File named "file.txt" for
reading.Select one correct answer.
Q50.Which of the following classes can be used to specify the character encoding
for input?Select one correct answer.
Q51.What is the name of collection interface used to maintain non-unique elements
in order?Select one correct answer.
Q52.What is the name of collection interface used to maintain unique elements?
Select one correct answer.
Q53.Which of the following methods is used to create a thread?
Select one correct answer.
Q54.Which of the following methods must be used in try-catch?
Select any two.
Q55.Which of the following methods can be written at line no.3 to make the program
compile correctly?Select one correct answer.
1 class abc imlements Runnable
2 {
3 //Here
4 }
Q56.Which of the following methods can be written at line no.3 to make the program
compile correctly?Select one correct answer.
1 class abc extends Thread
2 {
3 //Here
4 }
Q57.What will be the result of compiling and running the given program?
Select one correct answer.
1 class Q57
2 {
3 public static void main(String arg[])
4 {
5 int j=0;
6 switch(1)
7 {
8 case 2: j+=1;
9 case 4: j+=2;
10 default: j+=3;
11 case 0: j+=4;
12 }
13 System.out.println(j);
13 }
14 }
Q58.What will be the result of compiling and running the given program?
Select one correct answer.
1 class Q58
2 {
3 public static void main(String args[])
4 {
5 int arr[] = new int[2];
6 System.out.println(arr[0]);
7 }
8 }
Q59.What will be the result of compiling and running the given program?
Select one correct answer.