This set of Java Multiple Choice Questions & Answers (MCQs) on “Character Wrapper Advance”.
1. Which of these methods of Character wrapper can be used to obtain the char value contained in Character object. Answer: c 2. Which of the following constant are defined in Character wrapper? Answer: d 3. Which of these is a super class of Character wrapper? Answer: d 4. Which of these methods is used to know whether a given Character object is part of Java’s Identifiers? Answer: c 5. Which of these coding techniques is used by method isDefined()? Answer: d 6. What will be the output of the following Java program? a) < 7. What will be the output of the following Java program? a) < 8. What will be the output of the following Java program? a) true false true 9. What will be the output of the following Java program? a) b 10. What will be the output of the following Java program? a) true
a) get()
b) getVhar()
c) charValue()
d) getCharacter()
Clarification: To obtain the char value contained in a Character object, we use charValue() method.
a) MAX_RADIX
b) MAX_VALUE
c) TYPE
d) All of the mentioned
Clarification: Character wrapper defines 5 constants – MAX_RADIX, MIN_RADIX, MAX_VALUE, MIN_VALUE & TYPE.
a) Long
b) Digits
c) Float
d) Number
Clarification: Number is an abstract class containing subclasses Double, Float, Byte, Short, Character, Integer and Long.
a) isIdentifier()
b) isJavaIdentifier()
c) isJavaIdentifierPart()
d) none of the mentioned
Clarification: None.
a) Latin
b) ASCII
c) ANSI
d) UNICODE
Clarification: isDefined() returns true if ch is defined by Unicode. Otherwise, it returns false.
class Output
{
public static void main(String args[])
{
int a = Character.MAX_VALUE;
System.out.print((char)a);
}
}
b) >
c) ?
d) $
Clarification: Character.MAX_VALUE returns the largest character value, which is of character ‘?’.
Output:
$ javac Output.java
$ java Output
?
class Output
{
public static void main(String args[])
{
int a = Character.MIN_VALUE;
System.out.print((char)a);
}
}
b) !
c) @
d) Space
Clarification: Character.MIN_VALUE returns the smallest character value, which is of space character ‘ ‘.
Output:
$ javac Output.java
$ java Output
class Output
{
public static void main(String args[])
{
char a[] = {'a', '5', 'A', ' '};
System.out.print(Character.isDigit(a[0])+ " ");
System.out.print(Character.isWhitespace(a[3])+ " ");
System.out.print(Character.isUpperCase(a[2]));
}
}
b) false true true
c) true true false
d) false false false
Clarification: 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
class Output
{
public static void main(String args[])
{
char a = (char) 98;
a = Character.toUpperCase(a);
System.out.print(a);
}
}
b) c
c) B
d) C
Clarification: None.
Output:
$ javac Output.java
$ java Output
B
class Output
{
public static void main(String args[])
{
char a = '@';
boolean x = Character.isLetter(a);
System.out.print(x);
}
}
b) false
c) @
d) B
Clarification: None.
Output:
$ javac Output.java
$ java Output
false