Share on Google+Share on Google+

SCJP Module-12 Question-5

Advertisement
The Sample program will test your understanding about the Locale Class in Java.

Given below the sample code :

1  import java.text.*;
2  import java.util.*;
3  public class dateclass {
4  public static void main(String args[]){
5  Locale locale = Locale.getDefault();
6  System.out.println(locale);
7  // Insert code here
8  System.out.println(locale);
9  DateFormat df = DateFormat.getDateInstance();
10 Date myDate = new Date();
11 String myString = df.format(myDate);
12 System.out.println(myString);}}

What will be at line 7 to print date in locale of Canada(French) ?

1. locale = new Locale("fr", "CA");
    Locale.setDefault(locale);

2. df.setLocale(Locale.CA);

3. locale = new Locale("fr", "CA");
    Locale.getDefault(locale);

4. locale = new Locale("fr", "CA");
    Locale.getLocale(locale);

Answer

(1)

 

Advertisements

Posted on: July 20, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.