• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Locale class

 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi friends!
as far as i know there is no static method setLocale() of Locale class.
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you are right ...Thanks for the correction everyone
 
You can thank my dental hygienist for my untimely aliveness. So tiny:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic