Java OCA OCP Practice Question 2679

Question

Consider the following program and choose the right option:

import java.util.Locale;

class Main {//from   ww  w.  ja v a 2 s.com
        public static void main(String []args) {
                Locale locale1 = new Locale("en");  //#1
                Locale locale2 = new Locale("en", "in");  //#2
                Locale locale3 = new Locale("th", "TH", "TH"); //#3
                Locale locale4 = new Locale(locale3); //#4
                System.out.println(locale1 + " " + locale2 + " " + locale3 + "
                " + locale4);
        }
}
a)       This program will print the following: en en_IN th_TH_TH_#u-nu-thai 
         th_TH_TH_#u-nu-thai./*from w w  w. j a v a  2 s.c o m*/

b)      This program will print the following: en en_IN th_TH_TH_#u-nu-thai
     (followed by a runtime exception).

c)      This program results in a compiler error at statement #1.

d)     This program results in a compiler error at statement #2.

e)      This program results in a compiler error at statement #3.

f)      This program results in a compiler error at statement #4.


f)

Note

The Locale class supports three constructors that are used in statements #1, #2, and #3; however, there is no constructor in the Locale class that takes another Locale object as argument, so the compiler gives an error for statement #4.




PreviousNext

Related