1)
Correct syntax to create a character object.
- char ch=new char('A');
- Char ch=new Char('A');
- Character ch=new Character('A');
- Character ch=Character('A');
Correct Answer: 3
Character ch=new Character('A')
Java provides a Wrapper class Character which provides number of useful methods for character manipulation.
2)
Correct method to check whether an entered character is space (whitespace) or not.
- boolean Character.isSpace(char val);
- boolean Character.isWhitespace(char val);
- boolean isWhitespace(char val);
- boolean isSpace(char val);
Correct Answer: 2
boolean Character.isWhitespace(char val);
System.out.printf() can be used to print mixed data (same as c programming) in java.
4)
What will be printed by following code snippet?
char ch='a';
System.out.println(Character.toUppercase("value is: "+ch));
- Error
- value is: a
- value is: A
- value is:
Correct Answer: 1
Error -
cannot find symbol
symbol : method toUppercase(char)
toUppercase() is not a correct method of Character class, correct method is toUpperCase().
5)
What will be the output by following code snippet?
char x=-1;
System.out.println("value is: " +x);
- Error
- value is: -1
- value is: 255
- value is: 65535
Correct Answer: 1
possible loss of precision
found : int
required: char