Java OCA OCP Practice Question 2250

Question

Given the following two property files in the mypkg package,

what does the following class output?

mypkg.container.properties 
name=generic 
number=2 

mypkg.container_en.properties 
name=Docker 
type=container 
package mypkg; /*from   ww w. ja va 2s.  c o m*/

import java.util.*; 

public class Main { 
   public static void main(String[] args) { 
      Locale.setDefault(new Locale("ja")); 
      ResourceBundle rb = ResourceBundle.getBundle("mypkg.container"); 
      String name = rb.getString("name");    // r1 
      String type = rb.getString("type");    // r2 
      System.out.println(name + " " + type);   
   } 
} 
  • A. Docker container
  • B. generic container
  • C. generic null
  • D. The code does not compile.
  • E. Line r1 throws an exception.
  • F. Line r2 throws an exception.


F.

Note

This code sets the default locale to Japanese and then tries to get a resource bundle for container in the mypkg package.

Since there is not a Japanese resource bundle available, it uses the default resource bundle mypkg.container.properties.

Line r1 successfully gets the value generic for the key name.

Line r2 throws a MissingResourceException because there is not a key type in the default resource bundle.

The English resource bundle has this key, but it is not in the resource bundle hierarchy.




PreviousNext

Related