Java OCA OCP Practice Question 2681

Question

Consider the following program and predict the output:

import java.util.Locale;

class Main {
        public static void main(String []args) {
                Locale locale = new Locale("navi", "pandora");  //#1
                System.out.println(locale);
        }
}
  • a) The program results in a compiler error at statement #1.
  • b) The program results in a runtime exception of NoSuchLocaleException.
  • c) The program results in a runtime exception of MissingResourceException.
  • d) The program results in a runtime exception of IllegalArgumentException.
  • e) The program prints the following: navi_PANDORA.


e)

Note

To create a Locale object using the constructor Locale (String language, String country), any String values can be passed; just attempting to create a Locale object will not result in throwing exceptions (other than a NullPointerException, which could be raised for passing null Strings).

The toString() method of Locale class returns a string representation of the Locale object consisting of language, country, variant, etc.




PreviousNext

Related