QINIT:1 
TXT:Here is part of the code for a class which implements the Runnable interface.
BLA:
TXT: 1.   public class Whiffler extends Object implements Runnable {
TXT: 2.     Thread myT ;
TXT: 3.     public void start(){
TXT: 4.        myT = new Thread( this );
TXT: 5.     }
BLA:
TXT: 6.     public void run(){
TXT: 7.        while( true ){
TXT: 8.           doStuff();
TXT: 9.     }
BLA:
TXT:10.     System.out.println("Exiting run");
TXT:11.   }
TXT:12.   // more class code
BLA:
TXT:Assume that the rest of the class defines doStuff, etc and that the class compiles without error. Also assume that a Java application creates a Whiffler object and calls the Whiffler start method, that no other direct calls to Whiffler methods are made an that the Thread in this object is the only one the application creates. Which of the following are correct statements ? [Select two valid answers]
CHK:a. The doStuff method will be called repeatedly.
CHK:b. The doStuff method will never be executed.
CHK:c. The doStuff method will execute at least one time.
CHK:d. The statement in line 10 will never be reached.
ERR:a Answer a is wrong. The Thread is never started so run is never executed.
ANS:b:Answer b is right, since myT.start() is never called, the Thread never runs.
ERR:c Answer c is wrong. The Thread is never started so run is never executed.
ANS:d:Answer d is right, since myT.start() is never called.
QTERM:1
QINIT:2
TXT:Here is a method which creates a number of String objects in the course of printing a count down sequence.
BLA:
TXT:1.   public void countDown() {
TXT:2.      for( int i = 10 ; i >= 0 ; i-- ){
TXT:3.         String tmp = Integer.toString( i );
TXT:4.         System.out.println( tmp );
TXT:5.      }
BLA:
TXT:6.      System.out.println("BOOM!");
TXT:7.   }
BLA:
TXT:When the program reaches line 6, how many of the String objects created in line 3 are eligible for garbage collection? Assume that the System.out object is not keeping a reference.
OPT:a. none
OPT:b. 1
OPT:c. 10
OPT:d. 11
ERR:a Answer a is wrong because only the last String object of the 11 created still has a reference.
ERR:b Answer b is wrong because only the last String object of the 11 created still has a reference.
ANS:c:Answer c is correct because only the last String object of the 11 created still has a reference.
ERR:d Answer d is wrong because even though the tmp variable is out of scope in line 6, the local variable still has a reference.
QTERM:2
QINIT:3
TXT:Select two of the following methods that are instance methods of the Thread class, excluding any methods deprecated in Java 1.2.
CHK:a. start()
CHK:b. stop()
CHK:c. run()
CHK:d. sleep( long msec )
ANS:a:Answer a is correct, start is an instance method of Thread which makes a new Thread runnable.
ERR:b Option b is wrong because stop is a deprecated method. It is felt that abruptly stopping a Thread may leave an object in a damaged condition.
ANS:c:Answer c is correct. The run method is the key to Thread operation.
ERR:d Answer d is wrong, suspend is a deprecated method because a suspended Thread may retain a lock on an important system object.
ERR:e Answer e is wrong because sleep is a static (class) method, not an instance method.
ANS:f Answer f is correct because all Java objects have a toString method.
QTERM:3
QINIT:4
TXT:You are writing a set of classes related to cooking and have created your own exception hierarchy derived from java.lang.Exception as follows:
BLA:
TXT:   Exception
TXT:   +-- BadTasteException
TXT:          +-- BitterException
TXT:          +-- SourException
BLA:
TXT:Your base class, "BaseCook" has a method declared as follows:
BLA:
TXT:   int rateFlavor(Ingredient[] list) throws BadTasteException
BLA:
TXT:A class, "TexMexCook", derived from BaseCook has a method which overrides BaseCook.rateFlavor().  Which of the following are legal declarations of the overriding method? [Select three valid answers]
CHK:a. int rateFlavor(Ingredient[] list) throws BadTasteException
CHK:b. int rateFlavor(Ingredient[] list) throws Exception
CHK:c. int rateFlavor(Ingredient[] list) throws BitterException
CHK:d. int rateFlavor(Ingredient[] list)
ANS:a:Yes, overriding methods can throw the same exception.
ERR:b No, the overriding method must throw the same exception or a subclass.
ANS:c:Yes, the overriding method can throw an exception which is a subclass of the original.
ANS:d:Yes, the overriding method does not have to throw an exception at all.
QTERM:4
QINIT:5
TXT:You are working on an aquarium simulation class named Aquarius. You already have a method which adds a Fish object to the aquarium and returns the remaining fish capacity. This method has the following declaration.
BLA:
TXT:     public int addFish( Fish f )
BLA:
TXT:Now you want to provide for adding a whole shoal of fish at once. The proposed method declaration is:
BLA:
TXT:     protected boolean addFish( Fish[] f )
BLA:
TXT:The idea being that it will return true if there is more room in the tank or false if the tank now too full. Which of the following statements about this proposal are true?
BLA:
OPT:a. This technique is called overloading.
OPT:b. This technique is called overriding.
OPT:c. The compiler will reject the new method because the return type is different.
OPT:d. The compiler will reject the new method because the access modifier is different.
ANS:a:Answer a is correct, this is overloading the method name addFish.
ERR:b Answer b is wrong, overriding would be if a method with the exact same signature and return type was created in a subclass.
ERR:c Answer c is wrong, overloading methods can have any return type.
ERR:d Answer d is wrong, overloading methods can have any access modifier.
QTERM:5
QINIT:6
TXT:You have created a TimeOut class as an extension of Thread, the purpose being to print a "Time's Up" message if the Thread is not interrupted within 10 seconds of being started.
BLA:
TXT:Here is the run method which you have coded.
TXT:1.   public void run(){
TXT:2.     System.out.println("Start!");
TXT:3.      try {
TXT:4.         Thread.sleep(10000 );
TXT:5.        System.out.println("Time's Up!");
TXT:6.      } catch(InterruptedException e) {
TXT:7.         System.out.println("Interrupted!");
TXT:8.      }
TXT:9.   }
BLA:
TXT:Given that a program creates and starts a TimeOut object, which of the following statements is true?
OPT:a. Exactly 10 seconds after the start method is called, "Time's Up!" will be printed.
OPT:b. Exactly 10 seconds after "Start!" is printed, "Time's Up!" will be printed.
OPT:c. The delay between "Start!" being printed and "Time's Up!" will be 10 seconds plus or minus one tick of the system clock.
OPT:d. If "Time's Up!" is printed you can be sure at least 10 seconds have elapsed since "Start!" was printed.
ERR:a Answers a, b and c are all wrong because the expiration of a sleep timer does not guarantee that a Thread will run, only that it can run.
ERR:b Answers a, b and c are all wrong because the expiration of a sleep timer does not guarantee that a Thread will run, only that it can run.
ERR:c Answers a, b and c are all wrong because the expiration of a sleep timer does not guarantee that a Thread will run, only that it can run.
ANS:d:Answer d is the only thing which can be said with confidence.
QTERM:6
QINIT:7
TXT:What is the output of the following program?
BLA:
TXT: 1.   class Base {
TXT: 2.     int x=3;
BLA:     
TXT: 3.     public Base() {}
BLA:     
TXT: 4.     public void show() {
TXT: 5.       System.out.print(" The value is " + x);
TXT: 6.     }
BLA:         
TXT: 7.   } 
BLA:   
TXT: 8.   class Derived extends Base {
TXT: 9.     int x=2;
BLA:     
TXT:10.     public Derived() {}
BLA:     
TXT:11.     public void show() {
TXT:12.       System.out.print(" The value is " + x);
TXT:13.     }
BLA:
TXT:14.   }
BLA:  
TXT:15.   public class Test {
BLA:
TXT:16.     public static void main(String args[]) {   
TXT:17.       Base b = new Derived();
TXT:18.       b.show();
TXT:19.       System.out.println("The value is " +b.x);
TXT:20.     } 
BLA:
TXT:21.   } // end of class Test  
OPT:a.  The value is 3 The value is 2
OPT:b.  The value is 2 The value is 3
OPT:c.  The value is 3 The value is 3
OPT:d.  The value is 2 The value is 2
ANS:b:Dynamic Method Dispatching
QTERM:7
QINIT:8
TXT:What is the output of the following code?
BLA:
TXT: 1.   public class Note {
BLA:
TXT: 2.     public static void main(String args[]) {
TXT: 3.       String name[] = {"Killer","Miller"};
TXT: 4.       String name0 = "Killer";        
TXT: 5.       String name1 = "Miller";
TXT: 6.       swap(name0,name1);
TXT: 7.       System.out.println(name0 + "," + name1);
TXT: 8.       swap(name);
TXT: 9.       System.out.println(name[0] + "," + name[1]); 
TXT:10.     }
BLA:      
TXT:11.     public static void swap(String name[]) {
TXT:12.       String temp;
TXT:13.       temp=name[0];
TXT:14.       name[0]=name[1];
TXT:15.       name[1]=temp;
TXT:16.     }  
BLA:      
TXT:17.     public static void swap(String name0,String name1) {
TXT:18.       String temp;
TXT:19.       temp=name0;
TXT:20.       name0=name1;
TXT:21.       name1=temp;
TXT:22.     }    
TXT:23.   } // end of Class Note   
OPT:a.   Killer,Miller followed by Killer,Miller
OPT:b.   Miller,Killer followed by Killer,Miller
OPT:c.   Killer,Miller followed by Miller,Killer 
OPT:d.   Miller,Killer followed by Miller,Killer
ANS:c:Objects are passed by references
QTERM:8
QINIT:9
TXT:What is the output of the following program?
BLA:
TXT: 1.   public class Q11 {
TXT: 2.     static String str1 = "main method with String[] args";
TXT: 3.     static String str2 = "main method with int[] args";
BLA:     
TXT: 5.     public static void main(String[] args) {
TXT: 6.        System.out.println(str1);
TXT: 7.     }
BLA:    
TXT:10.     public static void main(int[] args) {
TXT:11.       System.out.println(str2); 
TXT:12.     }               
TXT:13.   }
OPT:a.   Duplicate method main(), compilation error at line 5.
OPT:b.   Duplicate method main(), compilation error at line 10. 
OPT:c.   Prints "main method with String[] args".  
OPT:d.   Prints "main method with int[] args".
ANS:c:Overloaded main method    
QTERM:9
QINIT:10
TXT:In the following applet, how many buttons will be displayed?
BLA:
TXT: 1.    import java.applet.*;
TXT: 2.    import java.awt.*;
BLA:
TXT: 3.    public class Q16 extends Applet {
TXT: 4.      Button okButton = new Button("Ok");
BLA:
TXT: 5.      public void init() {
TXT: 6.        add(okButton);
TXT: 7.        add(okButton);
TXT: 8.        add(okButton);     
TXT: 9.        add(okButton);     
BLA:            
TXT:10.        add(new Button("Cancel"));     
TXT:14.        add(new Button("Cancel"));
TXT:15.        add(new Button("Cancel"));     
TXT:16.        add(new Button("Cancel"));     
BLA:            
TXT:18.        setSize(300,300);     
TXT:19.      }
TXT:20.    } 
OPT:a.  1 Button with label "Ok" and 1 Button with label "Cancel".
OPT:b.  1 Button with label "Ok" and 4 Buttons with label "Cancel".
OPT:c.  4 Buttons with label "Ok" and 1 Button with label "Cancel".
OPT:d.  4 Buttons with label "Ok" and 4 Buttons with label "Cancel".
ANS:b:okButton already added once    
QTERM:10
QINIT:11
TXT:What is the output of the following program?
BLA:
TXT: 1.    class Test {
TXT: 2.      void show() {      
TXT: 3.         System.out.println("non-static method in Test");
TXT: 4.      }
TXT: 5.    }
BLA:
TXT: 6.    public class Q3 extends Test {
BLA:    
TXT: 7.      static void show() {
TXT: 8.         System.out.println("Overridden non-static method in Q3");
TXT: 9.      }
BLA:            
TXT:10.      public static void main(String[] args) {
TXT:11.         Q3 a = new Q3();
TXT:12.      }
TXT:13     }
OPT:a.   Compilation error at line 2. 
OPT:b.   Compilation error at line 7. 
OPT:c.   No compilation error, but runtime exception at line 2.
OPT:d.   No compilation error, but runtime exception at line 7.
ANS:b:A static method cannot be overrriden to be made non-static & vice-versa
QTERM:11
QINIT:12
TXT:What will happen if you compile/run the following code?
BLA:
TXT: 1.   public class Q21 {
TXT: 2.      int maxElements; 
BLA:
TXT: 3.      void Q21() {      
TXT: 4.        maxElements = 100;
TXT: 5.        System.out.println(maxElements); 
TXT: 6.      }     
BLA:
TXT: 7.      Q21(int i) {
TXT: 8.        maxElements = i;
TXT: 9.        System.out.println(maxElements);          
TXT:10.      }     
BLA:
TXT:11.      public static void main(String[] args) {
TXT:12.        Q21 a = new Q21();
TXT:13.        Q21 b = new Q21(999);
TXT:14.    
TXT:15.      }
TXT:16.   }             
OPT:a.   Prints 100 and 999.
OPT:b.   Prints 999 and 100.
OPT:c.   Compilation error at line 2, variable maxElements was not initialized.
OPT:d.   Compilation error at line 12.
ANS:d:No matching constructor found, void Q21() is a normal method.
QTERM:12
QINIT:13
TXT:Given the following class definition, which of the following methods could be legally placed after the comment //Here
BLA:
TXT:1.   public class Rid {
TXT:2.      public void amethod(int i, String s){}
TXT:3.      //Here
TXT:4.   }
BLA:
TXT:[Select two valid answers]
CHK:a.   public void amethod(String s, int i) {}
CHK:b.   public int  amethod(int i, String s) {} 
CHK:c.   public void amethod(int i, String mystring) {} 
CHK:d.   public void Amethod(int i, String s) {}
ANS:a:The overloading of method depends on the formal parameters and not return type 
ANS:d:It doesn't depend on the name of the parameters
QTERM:13
QINIT:14
TXT:Given the following class definition, which of the following statements would be legal after the comment //Here
BLA:
TXT: 1.    class InOut {
TXT: 2.       String s= new String("Between");
BLA:
TXT: 3.       public void amethod(final int iArgs) {
TXT: 4.          int iam;
TXT: 5.          class Bicycle{
TXT: 6.              public void sayHello(){
TXT: 7.                    //Here
TXT: 8.              } //End of bicycle class
TXT: 9.          }
TXT:10.       } //End of amethod
BLA:         
TXT:11.       public void another() {
TXT:12.        int iOther;
TXT:13.       }
TXT:14.    }
BLA:
TXT:[Select two valid answers]
CHK:a. System.out.println(s); 
CHK:b. System.out.println(iOther);
CHK:c. System.out.println(iam);
CHK:d. System.out.println(iArgs);
ANS:a:Because enclosing variables can be accessed.
ANS:d:Final arguments can be seen by the inner class in a method.
QTERM:14
QINIT:15
TXT:Which of the following methods are members of the Vector class and allow you to input a new element
BLA:
TXT:[Select one valid answer]
CHK:a. addElement()
CHK:b. insert()
CHK:c. append()
CHK:d. addItem()
ANS:a:addElement() puts a a new object into the Vector.
QTERM:15
QINIT:16
TXT:What will happen when we try to compile the following code.
BLA:
TXT: 1.   public void WhichArray( Object x ) {
BLA:
TXT: 2.     if( x instanceof int[] ) {
TXT: 3.       int[] n = (int[]) x ;
TXT: 4.       for( int i = 0 ; i < n.length ; i++ ){
TXT: 5.         System.out.println("integers = " + n[i] );
TXT: 6.       }
TXT: 7.     }    
BLA:
TXT: 8.     if( x instanceof String[] ) {
TXT: 9.       System.out.println("Array of Strings");
TXT:10.    }
TXT:11.   }
OPT:a. The compiler objects to line 2 comparing an Object with an array.
OPT:b. The compiler objects to line 3 casting an Object to an array of int primitives.
OPT:c. The compiler objects to line 7 comparing an Object to an array of Objects.
OPT:d. It compiles without error.
ERR:a. Answers a, b, and c are wrong, array references are treated like other Objects by the instanceof operator. 
ERR:b. Answers a, b, and c are wrong, array references are treated like other Objects by the instanceof operator.  
ERR:c. Answers a, b, and c are wrong, array references are treated like other Objects by the instanceof operator.  
ANS:d:Answer d is correct, this is a perfectly good code.
QTERM:16
QINIT:17
TXT:Consider the following class
BLA:
TXT: 1.   class Tester {
TXT: 2.      void test (int i)    { System.out.println ("int version"); }
TXT: 3.      void test (String s) { System.out.println ("String version"); } 
TXT: 4. 
TXT: 5.      public static void main (String args[]) {
TXT: 6.        Tester c = new Tester ();
TXT: 7.        char ch = 'p'; 
TXT: 8.        c.test (ch);
TXT: 9.      }
TXT:10.   }
BLA:
TXT:Which of the following statements below is true?(Choose one.)
OPT:a. Line 3 will not compile, because void methods cannot be overridden.
OPT:b. Line 8 will not compile, because there is no conversion of test() that takes a char argument.        
OPT:c. The code will compile and produce the follwing output "int version"
OPT:d. The code will compile and produce the follwing output "String version" 
ANS:c:Answer c is correct. At line 8, the char argument ch is  widened to type int (a method-call conversion), and passed to the int version of method test().
QTERM:17
QINIT:18
TXT:You are creating a ToolBase class which will be extended by other programmers. The ToolBase class contains a single abstract method, createTool.
BLA:
TXT:Which of the following statements are true? [Select two valid answers]
CHK:a. The ToolBase class must be declared abstract.
CHK:b. Classes extending ToolBase must not be declared abstract.
CHK:c. The ToolBase class must not be declared final.
CHK:d. The following variable declaration is illegal in any context "ToolBase myTB;"
ANS:a:Option a is correct because any class with one or more abstract methods can not be instantiated and therefore most be declared abstract.
ANS:c:Option c is correct, the modifiers abstract and final are mutually exclusive.
QTERM:18
QINIT:19
TXT:Given the following hierarchical relationship of several classes.
BLA:
TXT: 1. Object
TXT: 2.  |---TypeA
TXT: 3.  |     |-----TypeAB
TXT: 4.  |     |-----TypeAC
TXT: 5.  |--------TypeY
BLA:
TXT:And given the following method definition
BLA:
TXT: 6.   public sayType(Object x ){
TXT: 7.     if(x instanceof Object )System.out.print("Object,");
TXT: 8.     if(x instanceof TypeA  )System.out.print("TypeA,");
TXT: 9.     if(x instanceof TypeAB )System.out.print("TypeAB,");
TXT:10.     if(x instanceof TypeAC )System.out.print("TypeAC,");
TXT:11.   }
TXT:What would the program output be if the following line was executed:
TXT:12.   sayType( new TypeAB() );
OPT:a. Object,
OPT:b. Object,TypeA,TypeAB,
OPT:c. TypeAB,
OPT:d. Object,TypeAC,
ANS:b:Answer b is correct because the instanceof operator returns true for the class of the x reference and all of the parent classes.
QTERM:19
QINIT:20
TXT:What happens on trying to compile and run the following code?
BLA:
TXT:1.   public class EqualsTest{
TXT:2.     public static void main(String args[]){
TXT:3.       Long LA = new Long( 9 ) ;
TXT:4.       Long LB = new Long( 9 ) ;
TXT:5.       if( LA == LB ) System.out.println("Equal");
TXT:6.       else System.out.println("Not Equal");
TXT:7.     }
TXT:8.   }
OPT:a. The program compiles but throws a runtime exception in line 5.
OPT:b. The program compiles and prints "Not Equal".
OPT:c. The program compiles and prints "Equal".
OPT:d. The program throws compilation error.
ANS:b: B is correct, when used with objects, the "==" operator tests for identity. Since LA and LB are different objects, the test fails.
QTERM:20
QINIT:21
TXT:Which one statement in true about the application below?
BLA:
TXT:1.   class StaticStuff {
TXT:2.     static int x = 10;
BLA:
TXT:3.     static { x += 5; }
BLA:
TXT:4.     public static void main(String args[]) {
TXT:5.       System.out.println("x = " + x);
TXT:6.     }
BLA:
TXT:7.     static { x /= 5; }
TXT:8.   }
OPT:a. The code compiles, and execution produces the output x = 10.
OPT:b. The code compiles, and execution produces the output x = 15.
OPT:c. The code compiles, and execution produces the output x = 3.           
OPT:d. Line 7 will not compile, because you can have only one static initializer.
ANS:c: C is correct, Since all SICs is run before JVM invokes main method()
QTERM:21
QINIT:22
TXT:Assume the the class AcLis implements the ActionListener interface. The code fragment below constructs a button ande gives it four action listeners. When the button is pressed, which action listener is the first to get its actionPerformed() method invoked?
BLA:
TXT: 1.   Button btn = new Button("Hello");
TXT: 2.   AcLis a1 = new AcLis();
TXT: 3.   AcLis a2 = new AcLis(); 
TXT: 4.   AcLis a3 = new AcLis();
BLA:
TXT: 5.   btn.addActionListener(a1);
TXT: 6.   btn.addActionListener(a2);
TXT: 7.   btn.addActionListener(a3);
TXT: 8.   btn.removeActionListener(a2);
TXT: 9.   btn.removeActionListener(a3);
TXT:10.   btn.addActionListener(a3);
TXT:11.   btn.addActionListener(a2);
OPT:a. a1 gets its actionPerformed() method invoked first.
OPT:b. a2 gets its actionPerformed() method invoked first.
OPT:c. a3 gets its actionPerformed() method invoked first.
OPT:d. It is impossible to know which listener will be first.
ANS:d:Event Delegation model.
QTERM:22
QINIT:23
TXT:Which statement or statements are true about the code listed below?
BLA:
TXT:1.   public class MyTextArea extends TextArea {
BLA:
TXT:2.     public MyTextArea(int nrows, int ncols) {
TXT:3.       enableEvents(AWTEvent.TEXT_EVENT_MASK);
TXT:4.     }
BLA:
TXT:5.     public void processTextEvent(TextEvent te) {
TXT:6.       System.out.println("Processing a text event");
TXT:7.     }
TXT:8.   }
BLA:
TXT:[Select three valid answers]
CHK:a. The source code must appear in a file called MyTextArea.java.
CHK:b. Between lines 2 and 3, a call should be made to super(nrows,ncols) so that the next component will have the correct size.
CHK:c. Between lines 6 and 7, the following code should appear "return true;"
CHK:d. Between lines 6 and 7, the following code should appear "super.processTextEvent(te);"
ANS:a:Name of the file must be same as that of the main class.
ANS:b:processEvent().
ANS:d:processEvent().
QTERM:23
QINIT:24
TXT:Which statement or statements are true about the code fragment listed below? (HINT The ActionListener and ItemListener interface each define a single method.)
BLA:
TXT:1.   class MyListener implements ActionListener, ItemListener {
TXT:2.     public void actionPerformed(ActionEvent e) {
TXT:3.       System.out.println("Action.");
TXT:4.     }
BLA:
TXT:5.     public void itemStateChanged(ItemEvent ie) {
TXT:6.       System.out.println("Item.");
TXT:7.     }
TXT:8.   }
OPT:a. The code compiles without error.
OPT:b. The code generates a compiler error at line 1.
OPT:c. The code generates a compiler error at line 2.
OPT:d. The code generates a compiler error at line 5.
ANS:a:Since the class can implement from multiple Interfaces.
QTERM:24
QINIT:25
TXT:A text field has a variable-width font. It is constructed by calling new TextField("iiiii"). What happens if you change the contents of the textfield to "wwwww"? (NOTE i is one of the narrowest characters, and w is one of the widest.)
OPT:a. The text field becomes wider.
OPT:b. The text field becomes narrower.
OPT:c. The text field stays the same width; to see the entire contents you have to scroll using -> and <-.
OPT:d. The text field stays the same width; to see you need to have a horizontal scroll bar.
ANS:c:The width would remain the same, you have to use -> or <-
QTERM:25
QINIT:26
TXT:Which statements about garbage collection are true? Select two valid answers
CHK:a. You can directly free the memory allocated by an object.
CHK:b. You can directly run the garbage collector whenever you want.
CHK:c. The garbage collector informs your object when it is about to be garbage collected.
CHK:d. The garbage collector runs in low-memory situations.
ANS:c:A low priority thread running, informs the object about GC
ANS:d:JVM tries its best to run GC under low memory situation.
QTERM:26
QINIT:27
TXT:The setForeground() and setBackground() methods are defined in the following class
OPT:a. Graphics
OPT:b. Container
OPT:c. Component
OPT:d. Applet
ANS:c:setColor() is defined in Graphics class, others are stupid.
QTERM:27
QINIT:28
TXT:What methods does JAVA define in the java.lang.Math class specifically for trigonometric calculations? Select two valid answers.
CHK:a. cos()
CHK:b. asin()
CHK:c. arctan()
CHK:d. sine()
ANS:a:cos() very simple.
ANS:b:asin() calculate sine inverse.
QTERM:28
QINIT:29
TXT:Imagine that there are two exception classes called Exception1 and Exception2 that descend from the Exception class. Given these two class definitions,
BLA:
TXT:1.   class First {
TXT:2.     void test() throws Exception1, Exception2 { . . . }
TXT:3.   }
BLA:
TXT:4.   class Second extends First {
TXT:5.     void test() { . . . }
BLA:
TXT:Create a class called Third that extends Second and defines a test() method. What exceptions can Third's test method throw? Select one valid answer.
CHK:a. Exception1
CHK:b. Exception2
CHK:c. no checked exceptions
CHK:d. any exceptions declared in the throws clause of the Third's test() method.
ANS:c:Since super class method is not throwing derived cannot throw either.
QTERM:29
QINIT:30
TXT:Given these code snippets,
BLA:
TXT:1.   Boolean b1 = new Boolean(true);
TXT:2.   Boolean b2 = new Boolean(true);
BLA:
TXT:which expressions are legal JAVA expressions that return true? Select one valid answer.
CHK:a. b1 == b2
CHK:b. b1.equals(b2)
CHK:c. b1 & b2
CHK:d. b1 || b2
ANS:b:Because b1 == b2 evaluates false and other are illegal
QTERM:30
QINIT:31
TXT:What will appear in the standard output when you run the Tester class?
BLA:
TXT: 1.   class Tester {
TXT: 2.     int var;
BLA:
TXT: 3.     Tester(double var) {
TXT: 4.       this.var = (int)var;
TXT: 5.     }
BLA:  
TXT: 6.     Tester(int var) {
TXT: 7.       this("hello");
TXT: 8.     }
BLA:
TXT: 9.     Tester(String s) {
TXT:10.       this();
TXT:11.       System.out.println(s);
TXT:12.     }
BLA:
TXT:13.     Tester() {
TXT:14.       System.out.println("good-bye");
TXT:15.     }
BLA:
TXT:16.     public static void main(String args[]) {
TXT:17.       Tester t = new Tester(5);
TXT:18.     }
OPT:a.  "hello"
OPT:b.  5
OPT:c.  "hello" followed by "good-bye"
OPT:d.  "good-bye" followed by "hello"
ANS:d:Go through the constructor properly.
QTERM:31
QINIT:32
TXT:What are the range of values for a variable of type short?
OPT:a.  -2^7 to 2^7-1
OPT:b.  0 to 2^8
OPT:c.  -2^15 to 2^15-1
OPT:d.  -2^15-1 to 2^15
ANS:c:It is represented in 2's complement notation.
QTERM:32
QINIT:33
TXT:Analyze the following two classes
BLA:
TXT:1.   class First {
TXT:2.     static int a = 3;
TXT:3.   }
BLA:
TXT:4.   final class Second extends First {
TXT:5.     void method() {
TXT:6.       System.out.println(a);
TXT:7.     }
TXT:8.   }
OPT:a.  Class First compiles, but class Second does not.
OPT:b.  Neither class compiles.
OPT:c.  Both classes compile, and if method() is invoked, it writes 3 to the output.
OPT:d.  Both classes compile, and if method() is invoked, it throws an exception.
ANS:c:There is absolutely nothing wrong with inheriting static var.
QTERM:33
QINIT:34
TXT:What String instance method would return true when invoked as follows?
BLA:
TXT:1.   a.method(b);
BLA:
TXT:where a equals "GROUNDhog" and b equals "groundHOG"?
OPT:a.  equals()
OPT:b.  toLowerCase()
OPT:c.  toUpperCase()
OPT:d.  equalsIgnoreCase()
ANS:d:Again case-insensitive comparing can only be done with equalsIgnoreCase.
QTERM:34
QINIT:35
TXT:What access control keyword should you use to enable other classes to access a method freely within its package, but to restrict classes iutside of the package from accessing that method? Select one valid answer.
CHK:a.  private
CHK:b.  public
CHK:c.  protected
CHK:d.  Do not supply an access control keyword (friendly).
ANS:d:protected does all outside the package for the subclass, others are nonsense.
QTERM:35
QINIT:36
TXT:What letters are written to the standard output with the following code?
BLA:
TXT: 1.   class Unchecked {
TXT: 2.     public static void main(String args[]) {
TXT: 3.       try {
TXT: 4.         method();
TXT: 5.       } catch(Exception e) { }
TXT: 6.     }
BLA:
TXT: 7.     static void method() {
TXT: 8.       try {
TXT: 9.         wrench();
TXT:10.         System.out.println("a");
TXT:11.       } catch(ArithmeticException e) {
TXT:12.           System.out.println("b");
TXT:13.       } finally {
TXT:14.           System.out.println("c");
TXT:15.       }
TXT:16.       System.out.println("d");
TXT:17.     }
BLA:
TXT:18.     static void wrench() {
TXT:19.       throw new NullPointerException();
TXT:20.     } 
TXT:21.   }
BLA:
TXT:[Select one valid answer]
CHK:a.  "a"
CHK:b.  "b"
CHK:c.  "c"
CHK:d.  "d"
ANS:c:exception thrown is not caught
QTERM:36
QINIT:37
TXT:If you would like to change the size of a Component, you can use the following method
OPT:a.  size()
OPT:b.  resize()
OPT:c.  setSize()
OPT:d.  dimension()
ANS:c:resize() is a deprecated method.
QTERM:37
QINIT:38
TXT:Which LayoutManager arranges components left to right and then top to bottom, centering each row as it moves to the next row?
OPT:a.  BorderLayout
OPT:b.  FlowLayout
OPT:c.  GridLayout
OPT:d.  CardLayout
ANS:b:FlowLayout does this, others have different orientn.
QTERM:38
QINIT:39
TXT:Which label names(s) are illegal? Select two valid answers.
CHK:a.  here:
CHK:b.  _there:
CHK:c.  this:
CHK:d.  2to1odds:
ANS:c: c is invalid, this cannot be used
ANS:d: d is inavlid, cannot begin with no.
QTERM:39
QINIT:40
TXT:Which keyword, when used in front of a method, must also appear in front of the class.
OPT:a.  synchronized
OPT:b.  abstract
OPT:c.  public
OPT:d.  private
ANS:b:An abstract method can be declared in abstract class.
QTERM:40
QINIT:41
TXT: Given this code snippet,
BLA:
TXT: 1.   try {
TXT: 2.     tryThis();
TXT: 3.     return;
TXT: 4.   } catch(IOException x1) {
TXT: 5.     System.out.println("exception 1");
TXT: 6.     return;
TXT: 7.   } catch(Exception x2) {
TXT: 8.     System.out.println("exception 2");
TXT: 9.     return;
TXT:10.   } finally {
TXT:11.     System.out.println("finally");
TXT:12.   }
BLA:
TXT:what will appear in the standard output if tryThis() throws a IOException?
OPT:a. "exception 1" followed by "finally"
OPT:b. "exception 2" followed by "finally"
OPT:c. "exception 1"
OPT:d. "exception 2"
ANS:a:Check out yourself
QTERM:41
QINIT:42
TXT:Given the code snippet,
BLA:
TXT:1.   double a = 90.7;
TXT:2.   double b = method(a);
TXT:3.   System.out.println(b);
BLA:
TXT:if this snippet displays 90.0 in the standard output, what Math method did method() invoke? Select one valid answer.
CHK:a.  abs()
CHK:b.  round()
CHK:c.  floor()
CHK:d.  ceil()
ANS:c:The other would return diff results.
QTERM:42
QINIT:43
TXT:What is written to the standard output given the following statement:
BLA:
TXT:1.  System.out.println(4 | 7);
OPT:a.  4
OPT:b.  5
OPT:c.  6
OPT:d.  7
ANS:d:Bitwise ORing
QTERM:43
QINIT:44
TXT:What expressions are true concerning the following lines of code?
BLA:
TXT:1.  int[] arr = {1, 2, 3};
TXT:2.  for(int i = 0 ; i < 2; i++)
TXT:3.    arr[i] = 0;
BLA:
TXT:[Select three valid answers]
CHK:a.  arr[0] == 0
CHK:b.  arr[1] == 2
CHK:c.  arr[1] == 0
CHK:d.  arr[2] == 3
ANS:a:valid
ANS:c:valid
ANS:d:valid
QTERM:44
QINIT:45
TXT:What will the following block of code write to standard output when it is executed?
BLA:
TXT: 1.   int i = 3;
TXT: 2.   int j = 0;
TXT: 3.   double k = 3.2;
TXT: 4.   if (i < k)
TXT: 5.      if (i == j)
TXT: 6.         System.out.println(i);
TXT: 7.      else
TXT: 8.         System.out.println(j);
TXT: 9.   else
TXT:10.     System.out.println(k);
OPT:a.  3
OPT:b.  0
OPT:c.  3.2
OPT:d.  None of these.
ANS:b:go through properly
QTERM:45
QINIT:46
TXT:What is the output of the following piece of code
TXT:1.   int x = 6;
TXT:2.   double d = 7.7;
BLA:
TXT:3.   System.out.println((x>d) ? 99.9 ; 9);
OPT:a.  9
OPT:b.  9.0
OPT:c.  99.9
OPT:d.  Nothing, an ArithmeticException is thrown at line 3.
ANS:b:Upward casting is done.
QTERM:46
QINIT:47
TXT:Which of the following are legal methods for the String class ? Select two valid answers.
CHK:a.  length()
CHK:b.  toUpper()
CHK:c.  toUppercase()
CHK:d.  equals()
ANS:a:returns the length of the string.
ANS:d:overridden from the Object class.
QTERM:47
QINIT:48
TXT:Consider the following
BLA:
TXT:1.   class A extends Integer {
TXT:2.      int x = 0;
TXT:3.   }
OPT:a.  The code will compile correctly.
OPT:b.  The code will not compile because Integer class is final.
OPT:c.  The code will not compile because A class doesn't have a constructor.
OPT:d.  The code will compile but an ArithmeticException at runtime.
ANS:b:Final class cannot be subclassed.
QTERM:48
QINIT:49
TXT:FlowLayout is the default layout manager for which of the following containers? Select two valid answers.
CHK:a.  Panel
CHK:b.  Applet
CHK:c.  Frame
CHK:d.  Dialog
ANS:a:see the JDK Documentation.
ANS:b:valid because applet is a sub class of Panel.
QTERM:49
QINIT:50
TXT:Using a FlowLayout Manager, which of the following is the correct way to add a component reference by the variable "c" to a container.
OPT:a.  add(c)
OPT:b.  c.add()
OPT:c.  add("Center",c)
OPT:d.  set(c)
ANS:a:All others are invalid.
QTERM:50
QINIT:51
TXT:Given the following code snippet
BLA:
TXT:1.   class A {
TXT:2.     public void method(int a, float b) { 
TXT:3.         // some declaration and etc. 
TXT:4.     } 
TXT:5.   } 
BLA:
TXT:6.    public class B extends A { 
TXT:7.      //Comment here ?
TXT:8.    }
BLA:
TXT:In class B which methods could replace (// Comment here ?) ?
BLA:
TXT:[Select three valid answers]
CHK:a. void method(int i, float a) 
CHK:b. public void method(int i, float f) 
CHK:c  public void method() 
CHK:d. protected int method(float f, int b) 
ANS:b:This is the example of over-riding.
ANS:c:All together a different method.
ANS:d:All together a different approach.
QTERM:51
QINIT:52
TXT:What does the following program do when it is run with the following command?
BLA:
TXT:   java Mystery Mighty Mouse
BLA:
TXT: 1.   class Mystery {
TXT: 2.      public static void main(String args[]) {
TXT: 3.        Changer c = new Changer();
TXT: 4.        c.method(args);
TXT: 5.        System.out.println(args[0] + " " + args[1]);
TXT: 6.      }
BLA:
TXT: 7.      static class Changer {
TXT: 8.        void method(String s[]) {
TXT: 9.         String temp = s[0];
TXT:10.         s[0] = s[1];
TXT:11.         s[1] = temp;
TXT:12.       }
TXT:13.     }
TXT:14.   }
OPT:a.  The program causes and ArrayIndexOutOfBoundsException to be thrown.
OPT:b.  The program runs but does not write anything to the standard output.
OPT:c.  The program writes "Mighty Mouse" to the standard output.
OPT:d.  The program writes "Mouse Mighty" to the standard output.
ANS:d:Since arrays are passed by reference.
QTERM:52
QINIT:53
TXT:What happens when you try to compile and run the following program?
BLA:
TXT: 1.   class Mystery {
TXT: 2.     String s;
TXT: 3.     public static void main(String args[]) {
TXT: 4.       Mystery m = new Mystery();
TXT: 5.       m.go();
TXT: 6.     }
BLA:
TXT: 7.     void Mystery() {
TXT: 8.       s = "Constructor";
TXT: 9.     }
BLA:
TXT:10.     void go() {
TXT:11.       System.out.println(s);
TXT:12.     }
TXT:13.   }
OPT:a. The code compiles and throws an exception at run time.
OPT:b. The code runs, but nothing appears in the standard output.
OPT:c. The code runs, and "constructor" appears in the standard output.
OPT:d. The code runs and writes "null" in the standard output.
ANS:d:Since void mystery() is a method with the class name.
QTERM:53
QINIT:54
TXT:What can you write at the comment //A in the following code so that this program writes the word "running" to the standard output?
BLA:
TXT: 1.   class RunTest implements Runnable {
BLA:
TXT: 2.     public static void main(String args[]) {
TXT: 3.       RunTest rt = new RunTest();
TXT: 4.       Thread t = new Thread(rt);
TXT: 5.       //A
TXT: 6.     }
BLA:
TXT: 7.     public void run() {
TXT: 8.       System.out.println("running");
TXT: 9.     }
BLA:
TXT:10.     void go() {
TXT:11.       start(1);
TXT:12.     }
BLA:
TXT:13.     void start(int i) {
TXT:14.     }
TXT:15.   } 
BLA:
TXT:[Select two valid answers]
CHK:a.  System.out.println("running");
CHK:b.  t.start();
CHK:c.  rt.start();
CHK:d.  rt.start(1);
ANS:a:Because thread was never started.
ANS:b:Since rt.start() would invoke the run method implemented.
QTERM:54
QINIT:55
TXT:What is wrong with the following code?
TXT:1.   final class First {
TXT:2.     private int a = 1;
TXT:3.     int b = 2;
TXT:4.   }
BLA:
TXT:5.   class Second extends First {
TXT:6.     public void method() {
TXT:7.       System.out.println(a+b);
TXT:8.     }
TXT:9.   }
OPT:a. You cannot invoke println() without passing it a string.
OPT:b. Because a is private, no classes other than First can access it.
OPT:c. Second cannot extend First.
OPT:d. final is not a valid keyword for a class.
ANS:c:Final class cannot be extended.
QTERM:55
QINIT:56
TXT:What is displayed when the following piece of code is executed.
BLA:
TXT: 1.    class Test extends Thread {
TXT: 2.      public void run() {
TXT: 3.        System.out.print("1 ");
TXT: 4.        yield();
TXT: 5.        System.out.print("2 ");
TXT: 6.        suspend();
TXT: 7.        System.out.print("3 ");
TXT: 8.        resume();
TXT: 9.        System.out.print("4 ");
TXT:10.      }
BLA:
TXT:11       public static void main(String []args) {
TXT:12.        Test t = new Test();
TXT:13.        t.start();
TXT:14.      }
TXT:15.    }
OPT:a.  Nothing, this is not a valid way to create and start a thread.
OPT:b.  1 2
OPT:c.  1 2 3
OPT:d.  1
ANS:b:a thread cannot unsuspend itself
QTERM:56
QINIT:57
TXT:What must be true for the RunHandler class so that the instances of RunHandler can be used as written in the following code?
BLA:
TXT:1.   class Test {
TXT:2.     public static void main(String args[]) {
TXT:3.       Thread t = new Thread(new RunHandler());
TXT:4.       t.start();
TXT:5.     }
TXT:6.   }
BLA:
TXT:[Select two valid answers]
CHK:a.  RunHandler must only implement the java.lang.Runnable interface.
CHK:b.  RunHandler must only extend the Thread class.
CHK:c.  RunHandler must extend the Thread class or implement Runnable interface.
CHK:d.  RunHandler must provide a run() method declared as public and returning void.
ANS:c:it is equivalent.
ANS:d:the run() must be public and void.
QTERM:57
QINIT:58
TXT:Which interface implementations can you add as listeners for a TextField object? Select three valid answers.
CHK:a.  ActionListener
CHK:b.  FocusListener
CHK:c.  MouseMotionListener
CHK:d.  ContainerListener
ANS:a:for entering etc.
ANS:b:receiving and transferring focus.
ANS:c:mouse motion tracking.
QTERM:58
QINIT:59
TXT:Which statements accurately describe the following line of code?
BLA:
TXT:     String s[][] = new String[10][];
BLA:
TXT:[Select one valid answer]
CHK:a.  This line of code is illegal.
CHK:b.  s is a two dimensional array containing 10 rows and 10 columns.
CHK:c.  s is an array of 10 arrays.
CHK:d.  Each element in s is set to "".
ANS:c:the entries are set to null via new operator.
QTERM:59
QINIT:60
TXT:To force a layout manager to re-layout the components in a container, you can invoke the container method called
OPT:a.  validate()
OPT:b.  repaint()
OPT:c.  layout()
OPT:d.  update();
ANS:a:forces the layout manager to update the components again.
QTERM:60
QINIT:61
TXT:You need a container to hold six equal-sized button in the three columns of two. This arrangement must persist when the container is resized. Which of the following will create the that container? 
OPT:a. Canvas c = new Canvas(new GridLayout(2,3));
OPT:b. Panel p = new Panel(new GridLayout(2,3));
OPT:c. Window w = new Window(new GridLayout(2,3));
OPT:d. Panel p = new Panel(new GridLayout(3,2));
ANS:b
QTERM:61
QINIT:62
TXT:The following lists the complete contents of the file named Derived.java:
BLA:
TXT:  1. public class Base extends Object {
TXT:  2.   String objType;
TXT:  3.   public Base() { objType = "I am a Base type"  ; }
TXT:  4. }
BLA:
TXT:  5. public class Derived extends Base {
TXT:  6.   public Derived() { objType = "I am a Derived type"; }
BLA:
TXT:  8.   public static void main(String args[]) {
TXT:  9.     Derived d = new Derived();
TXT: 10.   }
TXT: 11. }
BLA:
TXT:What will happen when this file is compiled?
OPT:a. Two class files,Base.class and Dervied.class, will be created.
OPT:b. The compiler will object to line 1.
OPT:c. The compiler will object to line 5.
OPT:d. The compiler will object to line 2.
ANS:b
QTERM:62
QINIT:63
TXT:Your mouseDragged() event handler and your paint method look like this	
BLA:
TXT:  1. public void mouseDragged(MouseEvent e) {
TXT:  2.   mouseX = e.getX();
TXT:  3.   mouseY = e.getY();
TXT:  4.   repaint();
TXT:  5. }
BLA:
TXT:  6. public void paint(Graphics g) {
TXT:  7.   g.setColor(Color.cyan);
TXT:  8.   g.drawLine(mouseX,mouseY,mouseX+10,mouseY+10);
TXT:  9. }
BLA:
TXT:You want to modify your code so that the cyan lines accumulate on the screen, rather than getting erased every time repaint() calls update(). What is the simplest way to proceed?
OPT:a. On line 4, replace repaint() with paint().
OPT:b. On line 4, replace repaint() with update().
OPT:c. After line 7, add this super.update(g);
OPT:d. Add public void update(Graphics g) { paint(g); }
ANS:d
QTERM:63
QINIT:64
TXT:Given the following code for the Demo class		
BLA:
TXT:  1. public class Demo {
TXT:  2.   private String userNames;
BLA:
TXT:  3.   public Demo() { 
TXT:  4.     userNames = new String[10];
TXT:  5.   }
BLA:
TXT:  6.   public void showName(int n) {
TXT:  7.     System.out.println("Name is " + userNames[n]);
TXT:  8.    }
TXT:  9. 
TXT: 10.   public String getName(int n) {
TXT: 11.     return(userNames[n];
TXT: 12.   }
TXT: 13. }
BLA:
TXT:What would be the result of calling the showName method with a parameter of 2 immediately after creating an instance of Demo
OPT:a. Standard output would show "Name is null".
OPT:b. A NullPointerException would be thrown, halting the program.
OPT:c. An ArrayIndexOutOfBoundsException would be thrown halting the program.
OPT:d. Standard output would show "Name is".
ANS:a
QTERM:64
QINIT:65
TXT:What will be the result of attempting to compile and run the following class?	
BLA:
TXT: 1. public class Integers {
TXT: 2.   public static void main(String args[]) {
TXT: 3.     System.out.printl(0x10 + 10 + 010);
TXT: 4.   } 
TXT: 5. }
BLA:
TXT:Select the one right answer.
OPT:a. The code won't compile. The compiler will complain about the expression 0x10 + 10 + 010
OPT:b. When run, the program will print "28"
OPT:c. When run, the program will print "34"
OPT:d. When run, the program will print "36"
ANS:c
QTERM:65
QINIT:66
TXT:How will the following program lay out its buttons?	
BLA:
TXT:  1. import java.awt.*;
BLA:
TXT:  2. public class MyClass {
TXT:  3.   public static void main(String args[]) {
TXT:  4.     String labels[] = {"A","B","C","D","E","F"};
BLA:
TXT:  5.     Window grid = new Frame();
TXT:  6.     grid.setLayout(new GridLayout(0,1,2,3));
BLA:    
TXT:  7.     for(int i=0;i<labels.length;i++) {
TXT:  8.       grid.add(new Button(labels[i]));
TXT:  9.     }
TXT: 10.     grid.pack(); 
TXT: 11.     grid.setVisible(true);
TXT: 12. }
BLA:
TXT:Select the one right answer
OPT:a. The program will not show any buttons at all.
OPT:b. It will place all buttons in one row - A B C D E F.
OPT:c. It will place all buttons in one column, i.e., each button in a separate row - A B C D E and F.
OPT:d. It will place pairs of buttons in three separate row A B, C D and E F.
ANS:c
QTERM:66
QINIT:67
TXT:What happens when this method is called with an input of "Java rules"?	
BLA:
TXT: 1. public String addOK(String S) {
TXT: 2.   S += " OK!";
TXT: 3.   return S;
TXT: 4. }
BLA:
TXT:Select one correct answer
OPT:a. The method will return "OK!";
OPT:b. A runtime exception will be thrown.
OPT:c. The method will return "Java rules OK!".
OPT:d. The method will return "Java rules".
ANS:c
QTERM:67
QINIT:68
TXT:What happens during execution of the following program?
BLA:
TXT: 1. public class OperandOrder {
TXT: 2.   public static void main(String args[]) {
TXT: 3.     int i=0;
TXT: 4.     int a[] = {3,6};
TXT: 5.     a[i] = i = 9;
TXT: 6.     System.out.println(i + " " + a[0] + " " + a[1]);
TXT: 7.   }
TXT: 8. }
BLA:
TXT:Select one correct answer.
OPT:a. Raises "ArrayIndexOutOfBoundsException".
OPT:b. Prints "9 9 6".
OPT:c. Prints "9 0 6".
OPT:d. Prints "9 3 6".
ANS:b
QTERM:68
QINIT:69
TXT:Which statements about the output of the following program are true?	
BLA:
TXT:  1. public class Logic {
TXT:  2.   public static void main(String args[]) {
TXT:  3.     int i = 0;
TXT:  4.     int j = 0;
TXT:  5.     boolean t = true;
TXT:  6.     boolean r;
BLA:
TXT:  7.     r = (t & 0<(i += 1));
TXT:  8.     r = (t && 0<(i += 2));
TXT:  9.     r = (t | 0<(j += 1));
TXT: 10.     r = (t || 0<(j += 2));
TXT: 11.     System.out.println(i + " " + j);
TXT: 12.   }
TXT: 13. }
BLA:
TXT:Select two the valid answers.
CHK:a. The first digit printed is 1.
CHK:b. The first digit printed is 3.
CHK:c. The second digit printed is 3.
CHK:d. The second digit printed is 1.
ANS:b
ANS:d
QTERM:69
QINIT:70
TXT:What kind of stream is the System.out object?	
OPT:a. java.io.BufferedWriter
OPT:b. java.io.PrintStream
OPT:c. java.io.FileWriter
OPT:d. java.io.OutputStreamWriter
ANS:b
QTERM:70
QINIT:71
TXT:Which of the following events has a matching adapter class that implements the appropriate listener interface?	
BLA:
TXT:[Select two correct answers]
CHK:a. java.awt.event.MouseEvent
CHK:b. java.awt.event.ActionEvent
CHK:c. java.awt.event.FocusEvent
CHK:d. java.awt.event.ItemEvent
ANS:a
ANS:c
QTERM:71
QINIT:72
TXT:Here is a partial listing of a class to represent a game board in a networked game. It is desired to prevent collisions due to more than one Thread using the addPic method to modify the array of Image references.	
BLA:
TXT:  1.  class Board extends Object {
TXT:  2.    Image[] pics = new Image[64];
TXT:  3.    int active = 0;
BLA:
TXT:  4.    public boolean addPic( Image mg, int pos) {
TXT:  5.      synchronized (this) { 
TXT:  6.        if (pics[pos] == null) 
TXT:  7.          { active++ ; pics[pos] = mg; return true; }
TXT:  8.        else
TXT:  9.          return false;  
TXT: 10.      }
TXT: 11.    }
TXT: 12.    // remainder of class 
BLA:
TXT:Select two alternatives for line 5 that would accomplish this.
CHK:a. synchronized (this)
CHK:b. synchronized (pics)
CHK:c. synchronized (mg)
CHK:d. synchronized (active)
ANS:a
ANS:b
QTERM:72
QINIT:73
TXT:Given an object created by the following class	
BLA:
TXT: 1.   class Example extends Object {
TXT: 2.     public void Increment (Integer N) {
TXT: 3.       N = new Integer( N.intValue() + 1);
TXT: 4.     }
BLA:
TXT: 6.     public void Result(int x) {
TXT: 7.       Integer X = new Integer(X);
TXT: 8.       Increment(X);
TXT: 9.       System.out.println("New value is" + X);
TXT: 10.    }
BLA:
TXT: 11.  }
BLA:
TXT:What happens when a program calls the Result method with a value of 30?
OPT:a. The message "New value is 31" goest to the standard output.
OPT:b. The message "New value is 29" goes to the standard output.
OPT:c. The message "New Value is 30" goes to the standard output.
OPT:d. The program fails to compile.
ANS:c
QTERM:73
QINIT:74
TXT:What is the output of the following program	
BLA:
TXT: 1.   public class Test { 
TXT: 2.     private int i = giveMeJ(); 
TXT: 3.     private int j = 10; 
TXT: 4. 
TXT: 5.     private int giveMeJ() { 
TXT: 6.       return j; 
TXT: 7.     } 
TXT: 8. 
TXT: 9.     public static void main(String args[]) { 
TXT: 10.      System.out.println((new Test()).i); 
TXT: 11.    } 
TXT: 12.  } 
BLA:
TXT:Select one correct answer
OPT:a. Compiler error complaining about access restriction of private variables of AQuestion.
OPT:b. Compiler error complaining about forward referencing.
OPT:c. No Compilation error - The output is 0;
OPT:d. No Compilation error - The output is 10;
ANS:c
QTERM:74
QINIT:75
TXT:What is the result of compiling the following program	
BLA:
TXT: 1.   public class Test { 
TXT: 2.     public static void main(String args[]) { 
TXT: 3.       System.out.println("Before Try"); 
TXT: 4.       try { 
TXT: 5.       } catch(java.io.IOException t) { 
TXT: 6.          System.out.println("Inside Catch"); 
TXT: 7.       } 
TXT: 8.       System.out.println("At the End"); 
TXT: 9.     } 
TXT: 10.  }
BLA:
TXT:Select one correct answer
OPT:a. No Compilation Error.
OPT:b. Compiler error complaining about the catch block where no IOException object can ever be thrown.
OPT:c. Compiler error - IOException not found. It must be imported in the first line of the code.
OPT:d. No compiler error. The lines "Before Try" and "At the end" are printed on the screen.
ANS:b
QTERM:75
QINIT:76
TXT:Read the following snippet carefully	
BLA:
TXT: 1.  public synchronized void someMethod() { 
TXT: 2.      //lots of code 
TXT: 3.      try { 
TXT: 4.        Thread.sleep(500); 
TXT: 5.      } catch(InterruptedException e) { 
TXT: 6.         //do some things here. 
TXT: 7.      } 
TXT: 8.      //more and more code here 
TXT: 9.  }
BLA:
TXT:[Select two valid answers]
CHK:a. The code causes compilation error  - sleep  cannot be called inside synchronized methods.
CHK:b. The Thread sleeps for at least 500 milliseconds in this method if not interrupted.
CHK:c. When the thread "goes to sleep" it releases the lock on the object.
CHK:d. The "sleeping" Threads always have the lock on the Object.
ANS:b
ANS:d
QTERM:76
QINIT:77
TXT:What will be the result of attempt to compile and the run the following code
BLA:
TXT: 1.  public class ADirtyOne { 
TXT: 2.    public static void main(String args[]) { 
TXT: 3.     System.out.println(Math.abs(Integer.MIN_VALUE)); 
TXT: 4.    } 
TXT: 5.  }
BLA:
TXT:Select one correct answer
OPT:a. Causes a compilation error.
OPT:b. Causes no error and the value printed on the screen is less than zero.
OPT:c. Causes no error and the value printed on the screen is one more than Integer.MAX_VALUE 
OPT:d. Will throw a runtime exception due to overflow - Integer.MAX_VALUE is less in magnitue than Integer.MIN_VALUE.
ANS:b
QTERM:77
QINIT:78
TXT:What is the result of attempting to compile and run the following program
BLA:
TXT: 1.   public class Test {
BLA:
TXT: 2.     public void method(Object o) { 
TXT: 3.       System.out.println("Object Version"); 
TXT: 4.     }
BLA:
TXT: 5.     public void method(String s) { 
TXT: 6.       System.out.println("String Version"); 
TXT: 7.     }
BLA:
TXT: 8.     public static void main(String args[]) { 
TXT: 9.       Test test = new Test(); 
TXT: 10.      test.method(null); 
TXT: 11.    }
TXT: 12.  }
BLA:
TXT:Select one correct answer
OPT:a. The code does not compile.
OPT:b. The code compiles cleanly and shows "Object Version".
OPT:c. The code compiles cleanly and shows "String Version".
OPT:d. The code throws an Exception at Runtime.
ANS:c
QTERM:78
QINIT:79
TXT:What is the result of attempting to compile the following program
BLA:
TXT: 1.   public class Test {
BLA:
TXT: 2.     public void method(StringBuffer sb) { 
TXT: 3.       System.out.println("StringBuffer Verion"); 
TXT: 4.     }
BLA:
TXT: 5.     public void method(String s) { 
TXT: 6.       System.out.println("String Version"); 
TXT: 7.     }
BLA:
TXT: 8.     public static void main(String args[]) { 
TXT: 9.       Test test = new Test(); 
TXT: 10.      test.method(null); 
TXT: 11.    }
TXT: 12.  }
BLA:
TXT:Select one correct answer
OPT:a. The code does not compile.
OPT:b. The code compiles correctly and shows "StringBuffer Version".
OPT:c. The code compiles correctly and shows "String Version".
OPT:d. The code throws an Exception at Runtime.
ANS:a
QTERM:79
QINIT:80
TXT:What is the requirement of the class which implements the following Interface
BLA:
TXT: 1.  public interface Test { 
TXT: 2.      void someMethod(); 
TXT: 3.  }
BLA:
TXT:[Select two valid answers]
CHK:a. Should have someMethod which must be necessarily declared as public.
CHK:b. Should have someMethod which could be "friendly" or public
CHK:c. Should have someMethod which should not throw any checked exceptions.
CHK:d. Should have someMethod which cannot be sychronized as sychronized is not in the signature of the interface definition.
ANS:a
ANS:c
QTERM:80
QINIT:81
TXT:What is the result of attempting to compile and run the following program?	
BLA:
TXT: 1.   public class AStringQuestion { 
TXT: 2.     static String s1; 
TXT: 3.     static String s2;
BLA:
TXT: 4.     public static void main(String args[]) { 
TXT: 5.       s2 = s1+s2; 
TXT: 6.       System.out.println(s2); 
TXT: 7.     } 
TXT: 8.   }
BLA:
TXT:[Select one correct answer]
OPT:a. Will cause a compilation error.
OPT:b. Runtime Execption - NullPointerException in the 2nd line of the main method.
OPT:c. Will compile successfully and print "nullnull" on the screen.
OPT:d. Will compile successfully and print an empty line on the screen.
ANS:c
QTERM:81
QINIT:82
TXT:What is the result of attempting to compile and run the following program?
BLA:
TXT: 1.   import java.io.*;
BLA:
TXT: 2.   public class OutOut { 
TXT: 3.     public static void main(String args[]) throws IOException { 
TXT: 4.       PrintStream pr = new PrintStream(new FileOutputStream("outfile")); 
TXT: 5.       System.out = pr; 
TXT: 6.       System.out.println("Lets see what I see now??"); 
TXT: 7.     } 
TXT: 8.   }
BLA:
TXT:[Select one correct answer]
OPT:a. The code causes a compiler error. out is a declared final in System and cannot be assigned to pr.
OPT:b. The code causes a runtime Exception due the assignment to a final variable.
OPT:c. The code compiles and runs success fully.  A file called "outfile" is created and "Lets see what I see now??" is printed in the same.
OPT:d. The code cause a compiler error. PrintStream is an abstract class
ANS:a
QTERM:82
QINIT:83
TXT:What is the result of attempting to compiler and run the following piece of code.	
BLA:
TXT: 1.   import java.awt.*;
BLA:
TXT: 2.   public class TestFrame extends Frame {
BLA:
TXT: 3.     public TestFrame() { 
TXT: 4.       Button one = new Button("One"); 
TXT: 5.       Button two = new Button("Two"); 
TXT: 6.       Button three = new Button("Three"); 
TXT: 7.       setLayout(new FlowLayout()); 
TXT: 8.       add(one); 
TXT: 9.       add(two); 
TXT: 10.      add(three); 
TXT: 11.      setSize(1000,1000); 
TXT: 12.      setVisible(true);
TXT: 13.      two.setVisible(false);  
TXT: 14.    } 
BLA:
TXT: 15.    public static void main(String args[]) { 
TXT: 16.      TestFrame tf = new TestFrame(); 
TXT: 17.    } 
TXT: 18.  }
BLA:
TXT:Select one correct answer
OPT:a. If the above code runs, the buttons - one and three are laid out in a single row from left to right with a gap in between. 
OPT:b. If the above code runs, the buttons - one and three are laid out in a single row from left to right with no gap in between.
OPT:c. Code does not compile - a component can not be hidden after being added to a container.
OPT:d. Code gets compiled successfully  but throws runtime Exception - a component can not be hidden after being added to a container.
ANS:a
QTERM:83
QINIT:84
TXT:What is the result of attempting to compile and run the following piece of code?	
BLA:
TXT: 1.   import java.awt.*;
BLA:
TXT: 2.   public class TestFrame extends Frame { 
TXT: 3.     public TestFrame() { 
TXT: 4.       CheckboxGroup chg = null; 
TXT: 5.       Checkbox ch = new Checkbox("Test",true,chg); 
TXT: 6.       setLayout(new FlowLayout()); 
TXT: 7.       add(ch); 
TXT: 8.       pack(); 
TXT: 9.       setVisible(true); 
TXT: 10.    } 
TXT: 11. 
TXT: 12.    public static void main(String args[]) { 
TXT: 13.      TestFrame tf = new TestFrame(); 
TXT: 14.    } 
TXT: 15.  }
BLA:
TXT:[Select one correct answer]
OPT:a. It will cause a compilation error as the checkbox group is null in the constructor. 
OPT:b. It will compile successfully but throws a runtime exception because the checkbox group is null in the constructor of the check box. 
OPT:c. It will compile and run successfully. The checkbox appears as a single radio button which is always true
OPT:d. It will compile and run successfully. The checkbox bears its original appearence and does not appear as a radio button.
ANS:d
QTERM:84
QINIT:85
TXT:What is the result of attempting to compile and run the following program?
BLA:
TXT: 1. public class Test { 
TXT: 2.   private int i = j; 
TXT: 3.   private int j = 10; 
TXT: 4.   
TXT: 5.   public static void main(String args[]) { 
TXT: 6.     System.out.println((new Test()).i); 
TXT: 7.   }
TXT: 8. }
BLA:
TXT:[Select one correct answer]
OPT:a. Compiler error complaining about access restriction of private variables of Test.
OPT:b. Compiler error complaining about forward referencing.
OPT:c. No error - The output is 0;
OPT:d. No error - The output is 10;
ANS:b
QTERM:85
QINIT:86
TXT:What is the result of attempting to compile and run the following program
BLA:
TXT: 1.   public class A { 
TXT: 2.     private void method1() throws Exception { 
TXT: 3.       throw new RuntimeException(); 
TXT: 4.     } 
BLA:
TXT: 6.     public void method2() { 
TXT: 7.       try { 
TXT: 8.         method1(); 
TXT: 9.       } catch(RuntimeException e) { 
TXT: 10.         System.out.println("Caught Runtime Exception"); 
TXT: 11.      } catch(Exception e) { 
TXT: 12.         System.out.println("Caught Exception"); 
TXT: 13.      } 
TXT: 14.    } 
BLA:
TXT: 15.    public static void main(String args[]) { 
TXT: 16.      A a = new A(); 
TXT: 17.      a.method2(); 
TXT: 18.    }
TXT: 19.  }
BLA:
TXT:[Select one correct answer]
OPT:a. It will not compile.
OPT:b. It will compile and show - "Caught Exception".
OPT:c. It will compile and show - "Caught Runtime Exception".
OPT:d. It will compile and show both the messages one after another in the order they appear.
ANS:c
QTERM:86
QINIT:87
TXT:Assume that Cat is a class and String[] args is the argument passed to the public static void main(String args[]) method of the class. The class is executed with the following command line string
BLA:
TXT:c;\somedirectory> java Cat 
BLA:
TXT:An expression in the main method is as follows 
BLA:
TXT: 1.   System.out.println(args.length);
BLA:
TXT:What is the result of attempting to compile and run the snipped.
OPT:a. The above expression will cause a '0' appear on the command line. 
OPT:b. It will throw a NullPointerException. 
OPT:c. It will cause a blank line to appear.
OPT:d. It will cause a comilation error at line 1 due to length.
ANS:a
QTERM:87
QINIT:88
TXT:Given the following snippet of code
BLA:
TXT: 1.   char c = -1; 
BLA:
TXT:What is the result of compiling the above snippet.
OPT:a. It will cause a compiler error as the range of character is between 0 and 2^16 - 1. Will request for an explicit cast. 
OPT:b. It will not cause a compiler error and c will have the value -1; 
OPT:c. The variable c will not represent any ascii character. 
OPT:d. The variable c will still be a unicode character.
ANS:a
QTERM:88
QINIT:89
TXT:Given the following code fragment.
BLA:
TXT: 1.   switch( x ) {
TXT: 2.     case 100:
TXT: 3.       System.out.println("One hundred"); break;
TXT: 4.     case 200:
TXT: 5.       System.out.println("Two hundred"); break;
TXT: 6.     case 300:
TXT: 7.       System.out.println("Three hundred"); break;
TXT: 8.   }
BLA:
TXT:Choose two valid declarations of x that will not cause a compiler error.
CHK:a. byte x = 100;
CHK:b. short x = 200;
CHK:c. int x = 300;
CHK:d. long x = 400;
ANS:b
ANS:c
QTERM:89
QINIT:90
TXT:What happens to the file system when the following code is run and the myFile object is created? Assume that name represents a valid path and file name for a file that does not presently exist.	
BLA:
TXT: 1.   File createFile(String name) {
TXT: 2.     File myFile = new File(name);
TXT: 3.     return myFile;
TXT: 4.   }
BLA:
TXT:[Select one valid answer]
CHK:a. A new empty file with that name is created but not opened.
CHK:b. The current directory changes to that specified in name
CHK:c. A new emty file with that name is created and opened.
CHK:d. None of the above
ANS:d
QTERM:90


