What is the output of the following?.
package mypkg; //www.ja v a2 s. c o m import java.util.*; public class MyResource extends ListResourceBundle { private int count = 0; @Override protected Object[][] getContents() { return new Object[][] {{"count", count++}}; } public static void main(String[] args) { ResourceBundle rb = ResourceBundle.getBundle("mypkg.MyResource"); System.out.println(rb.getObject("count") + " " + rb.getObject("count")); } }
A.
This class correctly creates a Java class resource bundle.
It extends ListResourceBundle and creates a 2D array as the property contents.
Since count is an int, it is autoboxed into an Integer.
In the main()
method, it gets the resource bundle without a locale and requests the count key.
Since Integer is a Java Object, it calls getObject()
to get the value.
The value is not incremented each time because the getContents()
method is only called once.
Therefore, Option A is correct.