Java OCA OCP Practice Question 2606

Question

Consider the following 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()));
        }
}

Which one of the following options correctly describes the behavior of this program?

  • 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 output.




PreviousNext

Related