Java OCA OCP Practice Question 3055

Question

Choose the correct option based on this program:

import java.util.*;

public class ResourceBundle_it_IT extends ListResourceBundle {
    public Object[][] getContents() {
        return contents;
    }/*from   w w w . j  a v a2  s  .c  o m*/
    static final Object[][] contents = {
                { "1", "Uno" },
                { "2", "Duo" },
                { "3", "Trie" },
    };
    public static void main(String args[]) {
        ResourceBundle resBundle =
                 ResourceBundle.getBundle("ResourceBundle",
                    new Locale("it", "IT", ""));
        System.out.println(resBundle.getObject(new Integer(1).toString()));
    }
}
  • a) this program prints the following: Uno
  • b) this program prints the following: 1
  • c) this program will throw a MissingResourceException
  • d) this program will throw a ClassCastException


a)

Note

this program correctly extends ListResourceBundle and defines a resource bundle for the locale it_IT.

the getObject() method takes String as an argument; this method returns the value of the matching key.

the expression new Integer(1).toString() is equivalent of providing the key "1", so the program prints Uno in the console.




PreviousNext

Related