aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Locale class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Locale class" Watch "Locale class" New topic
Author

Locale class

Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Which one of the following statements creates a Locale
object for the United States?
A) Locale l = new Local(Locale.US);
B) Locale l = Locale.US;
C) Locale l = Locale.setLocale(Locale.US);

The answer is (B),
What about option A) and C)!
What exactly are they doing?


Source: Whizlab!

Thanks,
cmbhatt
[ April 27, 2007: Message edited by: Chandra Bhatt ]

cmbhatt
megha joshi
Ranch Hand

Joined: Feb 20, 2007
Posts: 206
Hi Chandra,



A) is using a Locale constructor to create a new Locale object
B) is not creating a new Locale object . New object is only created through constructors. Locale.US is a static Locale object provided in the API library, many other such static locale objects are available to use. So here we are just making a reference variable l of type Locale and pointing it to existing static Locale object -> Locale.US
C) is not creating a new object. It is setting the current locale to the existing static Locale object.

Hope this helps.
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Ok Megha,

But option 'B' reaches to answer, as ref variable l is assigned Locale.US;
l can be used anywhere where new Locale of US is required.

Isn't it?




Thanks,
cmbhatt
megha joshi
Ranch Hand

Joined: Feb 20, 2007
Posts: 206
Yes you are right...but read this again

Which one of the following statements creates a Locale
object for the United States?

It doesnt create a new object...so its not included in answer
[ April 26, 2007: Message edited by: megha joshi ]
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
I agree, "new" operator only creates a new object on the heap.

Will we be facing such a horrible questions too? A little miss interpretation
can cost us dear!!!

And last I would say, "b" is also correct if, a US Locale has to be used in the program.

There is no such method named setLocale();
There is setDefault(Locale ..); in the Locale class


Thanks Megha,
cmbhatt
[ April 26, 2007: Message edited by: Chandra Bhatt ]
Sonam Zam
Greenhorn

Joined: Apr 18, 2007
Posts: 9
hi friends!
as far as i know there is no static method setLocale() of Locale class.
raj malhotra
Ranch Hand

Joined: Feb 22, 2007
Posts: 285
Megha Joshi:

A) is using a Locale constructor to create a new Locale object


There is no constructor with Locale type as argument.
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Yeah Raj, That is true!

That is why, option "b" is surely correct!




Regards,
cmbhatt
megha joshi
Ranch Hand

Joined: Feb 20, 2007
Posts: 206
Yes you are right ...Thanks for the correction everyone
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Locale class
 
Similar Threads
"LocaleBug"
java.util.*;
how to show all countries currency symbols
java.util.ResourceBundle
Change JVM locale before Start up