Q.1

What will be the output of the program?

public class Test 
{ 
    private static int[] x; 
    public static void main(String[] args) 
    { 
        System.out.println(x[0]); 
    } 
}
  • null
  • Compile Error
  • NullPointerException at runtime
Q.2

Which two statements are true about comparing two instances of the same class, given that the equals() and hashCode() methods have been properly overridden?

  1. If the equals() method returns true, the hashCode() comparison == must return true.
  2. If the equals() method returns false, the hashCode() comparison != must return true.
  3. If the hashCode() comparison == returns true, the equals() method must return true.
  4. If the hashCode() comparison == returns true, the equals() method might return true.
  • 1 and 4
  • 2 and 3
  • 3 and 4
  • 1 and 3
Q.3

Which is valid declaration of a float?

  • float f = 1F;
  • float f = 1.0;
  • float f = "1";
  • float f = 1.0d;
Q.4

Which class does not override the equals() and hashCode() methods, inheriting them directly from class Object?

  • java.lang.String
  • java.lang.Double
  • java.lang.StringBuffer
  • java.lang.Character
Q.5

Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?

  • java.util.HashSet
  • java.util.LinkedHashSet
  • java.util.List
  • java.util.ArrayList
Q.6

What will be the output of the program?

import java.util.*; 
class I 
{
    public static void main (String[] args) 
    {
        Object i = new ArrayList().iterator(); 
        System.out.print((i instanceof List)+","); 
        System.out.print((i instanceof Iterator)+","); 
        System.out.print(i instanceof ListIterator); 
    } 
}
  • Prints: false, false, false
  • Prints: false, false, true
  • Prints: false, true, false
  • Prints: false, true, true
Q.7

/* 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;
Q.8

You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order. Which interface provides that capability?

  • java.util.Map
  • java.util.Set
  • java.util.List
  • java.util.Collection
Q.9

Which interface does java.util.Hashtable implement?

  • Java.util.Map
  • Java.util.List
  • Java.util.HashTable
  • Java.util.Collection
0 h : 0 m : 1 s