• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Locale class

 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
megha joshi
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends!
as far as i know there is no static method setLocale() of Locale class.
 
raj malhotra
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah Raj, That is true!

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




Regards,
cmbhatt
 
megha joshi
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you are right ...Thanks for the correction everyone
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic