What is the output of the following?.
package mypkg; // w ww.j ava2 s .com 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.getString("count") + " " + rb.getString("count")); } }
F.
This class correctly creates and retrieves a Java class resource bundle.
Since count is an int, it is autoboxed into an Integer.
However, rb.getString()
cannot be called for an Integer value.
The code throws a ClassCastException, so Option F is the answer.
If this was fixed, the answer would be Option C because the pre-increment is used and getContents()
is only called once.