• ০০।
     import java.awt.*; class Ticker extends Component { public static void main (String [] args) { Ticker t = new Ticker(); /* Missing Statements? */ } } 
    which two of the following statements, inserted independently, could legally be inserted into missing section of this code?
    1. boolean test = (Component instanceof t);
    2. boolean test = (t instanceof Ticker);
    3. boolean test = t.instanceof(Ticker);
    4. boolean test = (t instanceof Component);
    • ক) 1 and 4
    • খ) 2 and 3
    • গ) 1 and 3
    • ঘ) 2 and 4
  • ০১।
     package testpkg.p1; public class ParentUtil { public int x = 420; protected int doStuff() { return x; } } package testpkg.p2; import testpkg.p1.ParentUtil; public class ChildUtil extends ParentUtil { public static void main(String [] args) { new ChildUtil().callStuff(); } void callStuff() { System.out.print("this " + this.doStuff() ); /* Line 18 */ ParentUtil p = new ParentUtil(); System.out.print(" parent " + p.doStuff() ); /* Line 20 */ } } 
    which statement is true?
    • ক) The code compiles and runs, with output this 420 parent 420.
    • খ) If line 18 is removed, the code will compile and run.
    • গ) If line 20 is removed, the code will compile and run.
    • ঘ) An exception is thrown at runtime.
  • ০২।
    /* Missing Statement? */ public class foo { public static void main(String[]args)throws Exception { java.io.PrintWriter out = new java.io.PrintWriter(); new java.io.OutputStreamWriter(System.out,true); out.println("Hello"); } } 
    What line of code should replace the missing statement to make this program compile?
    • ক) No statement required.
    • খ) import java.io.*;
    • গ) include java.io.*;
    • ঘ) import java.io.PrintWriter;
  • ০৩।
    /* Missing statements? */ public class NewTreeSet extends java.util.TreeSet { public static void main(String [] args) { java.util.TreeSet t = new java.util.TreeSet(); t.clear(); } public void clear() { TreeMap m = new TreeMap(); m.clear(); } } 
    which two statements, added independently at beginning of the program, allow the code to compile?
    1. No statement is required
    2. import java.util.*;
    3. import.java.util.Tree*;
    4. import java.util.TreeSet;
    5. import java.util.TreeMap;
    • ক) 1 only
    • খ) 2 and 5
    • গ) 3 and 4
    • ঘ) 3 and 5
  • ০৪। Assume the following method is properly synchronized and called from a thread A on an object B:wait(2000);After calling this method, when will the thread A become a candidate to get another turn at the CPU?
    • ক) After thread A is notified, or after two seconds.
    • খ) After the lock on B is released, or after two seconds.
    • গ) Two seconds after thread A is notified.
    • ঘ) Two seconds after lock B is released.
  • ০৫।
    class A { protected int method1(int a, int b) { return 0; } } 
    Which is valid in a class that extends class A?
    • ক) public int method1(int a, int b) {return 0; }
    • খ) private int method1(int a, int b) { return 0; }
    • গ) public short method1(int a, int b) { return 0; }
    • ঘ) static protected int method1(int a, int b) { return 0; }
  • ০৬।
    class Bar { } class Test { Bar doBar() { Bar b = new Bar(); /* Line 6 */ return b; /* Line 7 */ } public static void main (String args[]) { Test t = new Test(); /* Line 11 */ Bar newBar = t.doBar(); /* Line 12 */ System.out.println("newBar"); newBar = new Bar(); /* Line 14 */ System.out.println("finishing"); /* Line 15 */ } } 
    At what point is the Bar object, created on line 6, eligible for garbage collection?
    • ক) after line 12
    • খ) after line 14
    • গ) after line 7, when doBar() completes
    • ঘ) after line 15, when main() completes
  • ০৭।
    class Boo { Boo(String s) { } Boo() { } } class Bar extends Boo { Bar() { } Bar(String s) {super(s);} void zoo() { // insert code here } } 
    which one create an anonymous inner class from within class Bar?
    • ক) Boo f = new Boo(24) { };
    • খ) Boo f = new Bar() { };
    • গ) Bar f = new Boo(String s) { };
    • ঘ) Boo f = new Boo.Bar(String s) { };
  • ০৮।
    class Foo { class Bar{ } } class Test { public static void main (String [] args) { Foo f = new Foo(); /* Line 10: Missing statement? */ } } 
    which statement, inserted at line 10, creates an instance of Bar?
    • ক) Foo.Bar b = new Foo.Bar();
    • খ) Foo.Bar b = f.new Bar();
    • গ) Bar b = new f.Bar();
    • ঘ) Bar b = f.new Bar();
  • ০৯।
    class HappyGarbage01 { public static void main(String args[]) { HappyGarbage01 h = new HappyGarbage01(); h.methodA(); /* Line 6 */ } Object methodA() { Object obj1 = new Object(); Object [] obj2 = new Object[1]; obj2[0] = obj1; obj1 = null; return obj2[0]; } } 
    Where will be the most chance of the garbage collector being invoked?
    • ক) After line 9
    • খ) After line 10
    • গ) After line 11
    • ঘ) Garbage collector never invoked in methodA()
  • ১০।
    class Test { private Demo d; void start() { d = new Demo(); this.takeDemo(d); /* Line 7 */ } /* Line 8 */ void takeDemo(Demo demo) { demo = null; demo = new Demo(); } } 
    When is the Demo object eligible for garbage collection?
    • ক) After line 7
    • খ) After line 8
    • গ) After the start() method completes
    • ঘ) When the instance running this code is made eligible for garbage collection.
  • ১১।
    class Test { public static void main(String [] args) { printAll(args); } public static void printAll(String[] lines) { for(int i = 0; i < lines.length; i++) { System.out.println(lines[i]); Thread.currentThread().sleep(1000); } } } 
    the static method Thread.currentThread() returns a reference to the currently executing Thread object. What is the result of this code?
    • ক) Each String in the array lines will output, with a 1-second pause.
    • খ) Each String in the array lines will output, with no pause in between because this method is not executed in a Thread.
    • গ) Each String in the array lines will output, and there is no guarantee there will be a pause because currentThread() may not retrieve this thread.
    • ঘ) This code will not compile.
  • ১২।
    class Test1 { public int value; public int hashCode() { return 42; } } class Test2 { public int value; public int hashcode() { return (int)(value^5); } } 
    which statement is true?
    • ক) class Test1 will not compile.
    • খ) The Test1 hashCode() method is more efficient than the Test2 hashCode() method.
    • গ) The Test1 hashCode() method is less efficient than the Test2 hashCode() method.
    • ঘ) class Test2 will not compile.
  • ১৩।
    class X implements Runnable { public static void main(String args[]) { /* Missing code? */ } public void run() {} } 
    Which of the following line of code is suitable to start a thread?
    • ক) Thread t = new Thread(X);
    • খ) Thread t = new Thread(X); t.start();
    • গ) X run = new X(); Thread t = new Thread(run); t.start();
    • ঘ) Thread t = new Thread(); x.run();
  • ১৪।
    class X2 { public X2 x; public static void main(String [] args) { X2 x2 = new X2(); /* Line 6 */ X2 x3 = new X2(); /* Line 7 */ x2.x = x3; x3.x = x2; x2 = new X2(); x3 = x2; /* Line 11 */ doComplexStuff(); } } 
    after line 11 runs, how many objects are eligible for garbage collection?
    • ক) 0
    • খ) 1
    • গ) 2
    • ঘ) 3
  • ১৫। Given a method in a protected class, what access modifier do you use to restrict access to that method to only the other members of the same class?
    • ক) final
    • খ) static
    • গ) private
    • ঘ) protected
    • ঙ) volatile
  • ১৬।
    import java.awt.Button; class CompareReference { public static void main(String [] args) { float f = 42.0f; float [] f1 = new float[2]; float [] f2 = new float[2]; float [] f3 = f1; long x = 42; f1[0] = 42.0f; } } 
    which three statements are true?
    1. f1 == f2
    2. f1 == f3
    3. f2 == f1[1]
    4. x == f1[0]
    5. f == f1[0]
    • ক) 1, 2 and 3
    • খ) 2, 4 and 5
    • গ) 3, 4 and 5
    • ঘ) 1, 4 and 5
  • ১৭।
    import java.io.*; public class MyProgram { public static void main(String args[]) { FileOutputStream out = null; try { out = new FileOutputStream("test.txt"); out.write(122); } catch(IOException io) { System.out.println("IO Error."); } finally { out.close(); } } } 
    and given that all methods of class FileOutputStream, including close(), throw an IOException, which of these is true?
    • ক) This program will compile successfully.
    • খ) This program fails to compile due to an error at line 4.
    • গ) This program fails to compile due to an error at line 6.
    • ঘ) This program fails to compile due to an error at line 18.
  • ১৮। In the given program, how many lines of output will be produced?
    public class Test { public static void main(String [] args) { int [] [] [] x = new int [3] [] []; int i, j; x[0] = new int[4][]; x[1] = new int[2][]; x[2] = new int[5][]; for (i = 0; i < x.length; i++) { for (j = 0; j < x[i].length; j++) { x[i][j] = new int [i + j + 1]; System.out.println("size = " + x[i][j].length); } } } } 
    • ক) 7
    • খ) 9
    • গ) 11
    • ঘ) 13
    • ঙ) Compilation fails
  • ১৯।
    interface Base { boolean m1 (); byte m2(short s); } 
    which two code fragments will compile?
    1. interface Base2 implements Base {}
    2. abstract class Class2 extends Base
      { public boolean m1(){ return true; }}
    3. abstract class Class2 implements Base {}
    4. abstract class Class2 implements Base
      { public boolean m1(){ return (7 > 4); }}
    5. abstract class Class2 implements Base
      { protected boolean m1(){ return (5 > 7) }}
    • ক) 1 and 2
    • খ) 2 and 3
    • গ) 3 and 4
    • ঘ) 1 and 5