Q.1

x =if (x1.hashCode() != x2.hashCode() )  x = x +if (x3.equals(x)  x = x +if (!x5.equals(x) x = x +if (x7.hashCode() == x8.hashCode() )  x = x +System.out.println("x = " + x);
and assuming that the equals() and hashCode() methods are properly implemented, if the output is "x = 1111", which of the following statements will always be true?
  • x2.equals(x1)
  • x3.hashCode() == x4.hashCode()
  • x5.hashCode() != x6.hashCode()
  • x8.equals(x7)
Q.2

class Test{
    public int value;
    public int hashCode() { return}
}
class Test{
    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.
Q.3

Which of the following are true statements?

  1. The Iterator interface declares only three methods: hasNext, next and remove.
  2. The ListIterator interface extends both the List and Iterator interfaces.
  3. The ListIterator interface provides forward and backward iteration capabilities.
  4. The ListIterator interface provides the ability to modify the List during iteration.
  5. The ListIterator interface provides the ability to determine its position in the List.
  • 2, 3, 4 and 5
  • 1, 3, 4 and 5
  • 3, 4 and 5
  • 1, 2 and 3
Q.4

What will be the output of the program?

public class Test 
{ 
    private static float[] f = new float[2]; 
    public static void main (String[] args) 
    {
        System.out.println("f[= " + f[0]); 
    } 
}
  • f[0] = 0
  • f[0] = 0.0
  • Compile Error
  • Runtime Exception
Q.5

What will be the output of the program?

public class Test 
{ 
    public static void main (String[] args) 
    {
        String foo = args[1]; 
        String bar = args[2]; 
        String baz = args[3]; 
        System.out.println("baz = " + baz); /* Line 8 */
    } 
}

And the command line invocation:

> java Test red green blue

  • baz =
  • baz = null
  • baz = blue
  • Runtime Exception
Q.6

Which statement is true for the class java.util.HashSet?

  • The elements in the collection are ordered.
  • The collection is guaranteed to be immutable.
  • The elements in the collection are guaranteed to be unique.
  • The elements in the collection are accessed using a unique key.
Q.7

What will be the output of the program?

package foo; 
import java.util.Vector; /* Line 2 */
private class MyVector extends Vector 
{
    int i =/* Line 5 */
    public MyVector() 
    { 
        i =
    } 
} 
public class MyNewVector extends MyVector 
{
    public MyNewVector () 
    { 
        i =/* Line*/
    } 
    public static void main (String args []) 
    { 
        MyVector v = new MyNewVector(); /* Line*/
    } 
}
  • Compilation will succeed.
  • Compilation will fail at line 3.
  • Compilation will fail at line 5.
  • Compilation will fail at line 15.
Q.8

What is the numerical range of char?

  • 0 to 32767
  • 0 to 65535
  • -256 to 255
  • -32768 to 32767
Q.9

Which interface provides the capability to store objects using a key-value pair?

  • Java.util.Map
  • Java.util.Set
  • Java.util.List
  • Java.util.Collection
Q.10

Which statement is true for the class java.util.ArrayList?

  • The elements in the collection are ordered.
  • The collection is guaranteed to be immutable.
  • The elements in the collection are guaranteed to be unique.
  • The elements in the collection are accessed using a unique key.
Q.11

What will be the output of the program?

import java.util.*; 
class H 
{
    public static void main (String[] args) 
    { 
        Object x = new Vector().elements(); 
        System.out.print((x instanceof Enumeration)+","); 
        System.out.print((x instanceof Iterator)+","); 
        System.out.print(x instanceof ListIterator); 
    } 
}
  • Prints: false,false,false
  • Prints: false,false,true
  • Prints: false,true,false
  • Prints: true,false,false
Q.12

What will be the output of the program?

public class Test 
{ 
    public static void main (String args[]) 
    {
        String str = NULL; 
        System.out.println(str); 
    } 
}
  • NULL
  • Compile Error
  • Code runs but no output
  • Runtime Exception
Q.13

Which of the following statements about the hashcode() method are incorrect?

  1. The value returned by hashcode() is used in some collection classes to help locate objects.
  2. The hashcode() method is required to return a positive int value.
  3. The hashcode() method in the String class is the one inherited from Object.
  4. Two new empty String objects will produce identical hashcodes.
  • 1 and 2
  • 2 and 3
  • 3 and 4
  • 1 and 4
Q.14

Which of the following are Java reserved words?

  1. run
  2. import
  3. default
  4. implement
  • 1 and 2
  • 2 and 3
  • 3 and 4
  • 2 and 4
Q.15

Which collection class allows you to associate its elements with key values, and allows you to retrieve objects in FIFO (first-in, first-out) sequence?

  • java.util.ArrayList
  • java.util.LinkedHashMap
  • java.util.HashMap
  • java.util.TreeMap
Q.16

What will be the output of the program?

TreeSet map = new TreeSet();
map.add("one");
map.add("two");
map.add("three");
map.add("four");
map.add("one");
Iterator it = map.iterator();
while (it.hasNext() ) 
{
    System.out.print( it.next() + " " );
}
  • one two three four
  • four three two one
  • four one three two
  • one two three four one
Q.17

What two statements are true about properly overridden hashCode() and equals() methods?

  1. hashCode() doesn't have to be overridden if equals() is.
  2. equals() doesn't have to be overridden if hashCode() is.
  3. hashCode() can always return the same value, regardless of the object that invoked it.
  4. equals() can be true even if it's comparing different objects.
  • 1 and 2
  • 2 and 3
  • 3 and 4
  • 1 and 3
Q.18

Which collection class allows you to access its elements by associating a key with an element's value, and provides synchronization?

  • java.util.SortedMap
  • java.util.TreeMap
  • java.util.TreeSet
  • java.util.Hashtable
Q.19

Suppose that you would like to create an instance of a new Map that has an iteration order that is the same as the iteration order of an existing instance of a Map. Which concrete implementation of the Map interface should be used for the new instance?

  • TreeMap
  • HashMap
  • LinkedHashMap
  • The answer depends on the implementation of the existing instance.
Q.20

What will be the output of the program?

public static void main(String[] args) 
{
    Object obj = new Object() 
    {
        public int hashCode() 
        {
            return        }
    }; 
    System.out.println(obj.hashCode()); 
}
  • 42
  • Runtime Exception
  • Compile Error at line 2
  • Compile Error at line 5
0 h : 0 m : 1 s