Home » JAVA Programming » Collections » Question
  1. What is the output of this program?
    import java.util.*;
    public class hashtable_Example
    {
    public static void main(String args[])
    {
    Hashtable object = new Hashtable();
    object.put("P", new Integer(12));
    object.put("Q", new Integer(21));
    object.put("R", new Integer(18));
    System.out.print(object.toString());
    }
    }
    1. {R=18, Q=21}
    2. {Q=21, P=12}
    3. {R=18, P=12}
    4. {R=18, Q=21, P=12}
    5. {P=12, R=18}
Correct Option: D

object.toString returns String equivalent of the hashtable, which can also be obtained by simply writing System.out.print(object); as print system automatically converts the object tostring equivalent.



Your comments will be displayed only after manual approval.