Java Questions & Answers – Locale & Random Classes

This section of our 1000+ Java MCQs focuses on Local & Random classes of Java Programming Language.

1. Which of these class produce objects with respect to geographical locations?
a) TimeZone
b) Locale
c) Date
d) SimpleTimeZone
View Answer

Answer: b
Explanation: The Locale class isinstantiated to produce objects that each describe a geographical or cultural region.

2. Which of these methods is not a Locale class?
a) UK
b) US
c) INDIA
d) KOREA
View Answer

Answer: c
Explanation: INDIA is not a Locale class.

3. Which of these class can generate pseudorandom numbers?
a) Locale
b) Rand
c) Random
d) None of the mentioned
View Answer

Answer: c
Explanation: None.
advertisement
advertisement

4. Which of these method of Locale class can be used to obtain country of operation?
a) getCountry()
b) whichCountry()
c) DisplayCountry()
d) getDisplayCountry()
View Answer

Answer: d
Explanation: None.

5. Which of these is a method can generate a boolean output?
a) retbool()
b) getBool()
c) nextBool()
d) nextBoolean()
View Answer

Answer: d
Explanation: None.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

6. What will be the output of the following Java program?

  1.     import java.util.*;
  2.     class LOCALE_CLASS
  3.     {
  4.         public static void main(String args[])
  5.         {
  6.             Locale obj = new Locale("INDIA") ;
  7.             System.out.print(obj.getCountry());
  8.         }
  9.     }

a) India
b) INDIA
c) Compilation Error
d) Nothing is displayed
View Answer

Answer: d
Explanation: None.
Output:

advertisement
$ javac LOCALE_CLASS.java
$ java LOCALE_CLASS

7. What will be the output of the following Java program?

advertisement
  1.     import java.util.*;
  2.     class LOCALE_CLASS
  3.     {
  4.         public static void main(String args[])
  5.         {
  6.             Locale obj = new Locale("HINDI", "INDIA") ;
  7.             System.out.print(obj.getCountry());
  8.         }
  9.     }

a) India
b) INDIA
c) Compilation Error
d) Nothing is displayed
View Answer

Answer: b
Explanation: None.
Output:

$ javac LOCALE_CLASS.java
$ java LOCALE_CLASS
INDIA

8. What will be the output of the following Java program?

  1.     import java.util.*;
  2.     class LOCALE_CLASS
  3.     {
  4.         public static void main(String args[])
  5.         {
  6.             Locale obj = new Locale("HINDI") ;
  7.             System.out.print(obj.getDisplayLanguage());
  8.         }
  9.     }

a) India
b) INDIA
c) HINDI
d) Nothing is displayed
View Answer

Answer: c
Explanation: None.
Output:

$ javac LOCALE_CLASS.java
$ java LOCALE_CLASS
HINDI

9. What will be the output of the following Java program?

  1.     import java.util.*;
  2.     class LOCALE_CLASS
  3.     {
  4.         public static void main(String args[])
  5.         {
  6.             Locale obj = new Locale("HINDI", "INDIA") ;
  7.             System.out.print(obj.getDisplayLanguage());
  8.         }
  9.     }

a) India
b) INDIA
c) HINDI
d) Nothing is displayed
View Answer

Answer: c
Explanation: None.
Output:

$ javac LOCALE_CLASS.java
$ java LOCALE_CLASS
HINDI

Sanfoundry Global Education & Learning Series – Java Programming Language.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.