Java Questions & Answers – Java.lang – Integer, Long & Character Wrappers

This section of our 1000+ Java MCQs focuses on Integer, Long & Character wrappers of Java Programming Language.

1. Which of these is a wrapper for data type int?
a) Integer
b) Long
c) Byte
d) Double
View Answer

Answer: a
Explanation: None.

2. Which of the following methods is a method of wrapper Integer for obtaining hash code for the invoking object?
a) int hash()
b) int hashcode()
c) int hashCode()
d) Integer hashcode()
View Answer

Answer: c
Explanation: None.

3. Which of these is a super class of wrappers Long, Character & Integer?
a) Long
b) Digits
c) Float
d) Number
View Answer

Answer: d
Explanation: Number is an abstract class containing subclasses Double, Float, Byte, Short, Integer and Long.
advertisement
advertisement

4. Which of these is a wrapper for simple data type char?
a) Float
b) Character
c) String
d) Integer
View Answer

Answer: b
Explanation: None.

5. Which of the following is method of wrapper Integer for converting the value of an object into int?
a) bytevalue()
b) int intValue();
c) Bytevalue()
d) Byte Bytevalue()
View Answer

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

6. Which of these methods is used to obtain value of invoking object as a long?
a) long value()
b) long longValue()
c) Long longvalue()
d) Long Longvalue()
View Answer

Answer: b
Explanation: long longValue() is used to obtain value of invoking object as a long.

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

advertisement
  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             char a[] = {'a', '5', 'A', ' '};   
  6.             System.out.print(Character.isDigit(a[0]) + " ");
  7.             System.out.print(Character.isWhitespace(a[3]) + " ");
  8.             System.out.print(Character.isUpperCase(a[2]));
  9.         }
  10.     }

a) true false true
b) false true true
c) true true false
d) false false false
View Answer

Answer: b
Explanation: Character.isDigit(a[0]) checks for a[0], whether it is a digit or not, since a[0] i:e ‘a’ is a character false is returned. a[3] is a whitespace hence Character.isWhitespace(a[3]) returns a true. a[2] is an uppercase letter i:e ‘A’ hence Character.isUpperCase(a[2]) returns true.
Output:

advertisement
$ javac Output.java
$ java Output
false true true

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

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             Integer i = new Integer(257);  
  6.             byte x = i.byteValue();
  7.             System.out.print(x);
  8.         }
  9.     }

a) 0
b) 1
c) 256
d) 257
View Answer

Answer: b
Explanation: i.byteValue() method returns the value of wrapper i as a byte value. i is 257, range of byte is 256 therefore i value exceeds byte range by 1 hence 1 is returned and stored in x.
Output:

$ javac Output.java
$ java Output
1

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

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             Integer i = new Integer(257);  
  6.             float x = i.floatValue();
  7.             System.out.print(x);
  8.         }
  9.     }

a) 0
b) 1
c) 257
d) 257.0
View Answer

Answer: d
Explanation: None.
Output:

$ javac Output.java
$ java Output
257.0

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

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             Long i = new Long(256);  
  6.             System.out.print(i.hashCode());
  7.         }
  8.     }

a) 256
b) 256.0
c) 256.00
d) 257.00
View Answer

Answer: a
Explanation: None.
Output:

$ javac Output.java
$ java Output
256

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.