Java OCA OCP Practice Question 2143

Question

Given the following two properties 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  www  .j  a  va 2  s .  c  o  m
import java.util.*; 
public class Main { 
   public static void main(String[] args) { 
      Locale.setDefault(new Locale("en")); 
      ResourceBundle rb = ResourceBundle.getBundle("mypkg.container"); 
      String name = rb.getString("name"); 
      String type = rb.getString("type"); 
      System.out.println(name + " " + type);   } 
} 
  • A. Docker container
  • B. generic container
  • C. generic null
  • D. None of the above


A.

Note

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

It finds the resource bundle mypkg.container_en.properties as the most specific match.

Both keys are found in this file, so Option A is the answer.




PreviousNext

Related