Java Questions & Answers – Java.lang – Character Wrapper Advance

This set of Java Multiple Choice Questions & Answers (MCQs) focuses on “Character Wrapper Advance”.

1. Which of these methods of Character wrapper can be used to obtain the char value contained in Character object.
a) get()
b) getVhar()
c) charValue()
d) getCharacter()
View Answer

Answer: c
Explanation: To obtain the char value contained in a Character object, we use charValue() method.

2. Which of the following constant are defined in Character wrapper?
a) MAX_RADIX
b) MAX_VALUE
c) TYPE
d) All of the mentioned
View Answer

Answer: d
Explanation: Character wrapper defines 5 constants – MAX_RADIX, MIN_RADIX, MAX_VALUE, MIN_VALUE & TYPE.

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

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

4. Which of these methods is used to know whether a given Character object is part of Java’s Identifiers?
a) isIdentifier()
b) isJavaIdentifier()
c) isJavaIdentifierPart()
d) none of the mentioned
View Answer

Answer: c
Explanation: None.

5. Which of these coding techniques is used by method isDefined()?
a) Latin
b) ASCII
c) ANSI
d) UNICODE
View Answer

Answer: d
Explanation: isDefined() returns true if ch is defined by Unicode. Otherwise, it returns false.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

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

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             int a = Character.MAX_VALUE;
  6.             System.out.print((char)a);
  7.         }
  8.     }

a) <
b) >
c) ?
d) $
View Answer

Answer: c
Explanation: Character.MAX_VALUE returns the largest character value, which is of character ‘?’.
Output:

advertisement
$ javac Output.java
$ java Output
?

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.             int a = Character.MIN_VALUE;
  6.             System.out.print((char)a);
  7.         }
  8.     }

a) <
b) !
c) @
d) Space
View Answer

Answer: d
Explanation: Character.MIN_VALUE returns the smallest character value, which is of space character ‘ ‘.
Output:

$ javac Output.java
$ java Output

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

  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:

$ javac Output.java
$ java Output
false true true

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

  1.     class Output
  2.     {
  3.         public static void main(String args[])
  4.         {
  5. 	    char a = (char) 98;
  6.             a = Character.toUpperCase(a);
  7.             System.out.print(a);
  8.         }
  9.     }

a) b
b) c
c) B
d) C
View Answer

Answer: c
Explanation: None.
Output:

$ javac Output.java
$ java Output
B

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

  1.     class Output
  2.     {
  3.         public static void main(String args[])
  4.         {
  5. 	    char a = '@';
  6.             boolean x = Character.isLetter(a);
  7.             System.out.print(x);
  8.         }
  9.     }

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

Answer: b
Explanation: None.
Output:

$ javac Output.java
$ java Output
false

Sanfoundry Global Education & Learning Series – Java Programming Language.

To practice all areas of Java language, here is complete set of 1000+ Multiple Choice Questions and Answers.

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.