What will be the output of the following Java code? [code] import java.util.*; class properties { public static void

What will be the output of the following Java code?
Code:
    import java.util.*;
    class properties 
    {
        public static void main(String args[]) 
        {
            Properties obj = new Properties();
            obj.put("AB", new Integer(3));
            obj.put("BC", new Integer(2));
            obj.put("CD", new Integer(8));
            System.out.print(obj.keySet());
        }
    }
A. {AB, BC, CD}
B. [AB, BC, CD]
C. [3, 2, 8]
D. {3, 2, 8}
 
Answer: b
Explanation: obj.keySet() returns a set containing all the keys used in properties object, here obj contains keys AB, BC, CD therefore obj.keySet() returns [AB, BC, CD].
Output:
Code:
$ javac properties.java
$ java properties
[AB, BC, CD].
 

Tìm kiếm

Back
Top