Q 1. What will be the output of the following Java program?
class mainclass {
public static void main(String args[])
{
char a = ‘A’;
a++;
System.out.print((int)a);
}
}
A. 64
B. 65
C. 67
D. 66
Show Answer
Answer:-D. 66Explanation
ASCII value of ‘A’ is 65, on using ++ operator character value increments by one. output:$ javac mainclass.java $ java mainclass 66Q 2. What will be the output of the following Java program?
class mainclass {
public static void main(String args[])
{
boolean var1 = true;
boolean var2 = false;
if (var1)
System.out.println(var1);
else
System.out.println(var2);
}
}
A. 0
B. 1
C. true
D. false
Show Answer
Answer:-C. trueExplanation
None. output:$ javac mainclass.java $ java mainclass trueQ 3. What will be the output of the following Java code?
class booloperators {
public static void main(String args[])
{
boolean var1 = true;
boolean var2 = false;
System.out.println((var1 & var2));
}
}
A. 0
B. 1
C. true
D. false
Show Answer
Answer:-D. falseExplanation
boolean ‘&’ operator always returns true or false. It returns true when both the values are true and false otherwise. Since, var1 is defined true and var2 is defined false hence their ‘&’ operator result is false. output:$ javac booloperators.java $ java booloperators falseQ 4. What will be the output of the following Java code?
class asciicodes {
public static void main(String args[]
{
char var1 = ‘A’;
char var2 = ‘a’;
System.out.println((int)var1 + ” ” + (int)var2);
}
}
A. 162
B. 67 95
C. 65 97
D. 66 98
Show Answer
Answer:-C. 65 97Explanation
ASCII code for ‘A’ is 65 and for ‘a’ is 97. output:$ javac asciicodes.java $ java asciicodes 65 97Q 5. What is the numerical range of a char data type in Java?
A. -128 to 127
B. 0 to 256
C. 0 to 32767
D. 0 to 65535
Show Answer
Answer:-D. 0 to 65535Explanation
Char occupies 16-bit in memory, so it supports 216 i:e from 0 to 65535.Q 6. Which of these coding types is used for data type characters in Java?
A. ASCII
B. ISO-LATIN-1
C. UNICODE
D. None of the mentioned
Show Answer
Answer:-C. UNICODEExplanation
Unicode defines fully international character set that can represent all the characters found in all human languages. Its range is from 0 to 65536.Q 7. Which of these values can a boolean variable contain?
A. True & False
B. 0 & 1
C. Any integer value
D. true
Show Answer
Answer:-A. True & FalseExplanation
Boolean variable can contain only one of two possible values, true and false.Q 8. Which of these occupy first 0 to 127 in Unicode character set used for characters in Java?
A. ASCII
B. ISO-LATIN-1
C. None of the mentioned
D. ASCII and ISO-LATIN1
Show Answer
Answer:-D. ASCII and ISO-LATIN1Explanation
First 0 to 127 character set in Unicode are same as those of ISO-LATIN-1 and ASCII.Q 9. Which one is a valid declaration of a boolean?
A. boolean b1 = 1;
B. boolean b2 = ‘false’;
C. boolean b3 = false;
D. boolean b4 = ‘true’
Show Answer
Answer:-C. boolean b3 = false;Explanation
Boolean can only be assigned true or false literals.Q 10. What will be the output of the following Java program?
class array_output {
public static void main(String args[])
{
char array_variable [] = new char[10];
for (int i = 0; i < 10; ++i) {
sarray_variable[i] = ‘i’;
System.out.print(array_variable[i] + “” );
i++;
}
}
}
A. i i i i i
B. 0 1 2 3 4
C. i j k l m
D. None of the mentioned
Show Answer
Answer:-A. i i i i iExplanation
output:$ javac array_output.java $ java array_output i i i i iQ 11. What is the size of a char data type in Java?
A. 8-bit
B. 16-bit
C. 32-bit
D. 64-bit
Show Answer
Answer:-B. 16-bitQ 12. Which character set does Java use to represent the char data type?
A. ASCII
B. Extended ASCII
C. Unicode (UTF-16)
D. ISO-8859-1
Show Answer
Answer:-C. Unicode (UTF-16)Q 13. What is the default value of a boolean variable when declared as a class member?
A. true
B. false
C. null
D. 0
Show Answer
Answer:-B. falseQ 14. What is the range of the char data type in Java?
A. -128 to 127
B. 0 to 255
C. 0 to 65,535
D. -32,768 to 32,767
Show Answer
Answer:-C. 0 to 65,535Q 15. Which of the following is a valid way to initialize a char?
A. char c = "A";
B. char c = 'Ab';
C. char c = 65;
D. char c = A;
Show Answer
Answer:-C. char c = 65;Q 16. What will be the output of: boolean b = 1;?
A. true
B. false
C. Compilation Error
D. Runtime Error
Show Answer
Answer:-C. Compilation ErrorQ 17. Which escape sequence represents a “tab” in a char literal?
A. \t
B. \b
C. \n
D. \r
Show Answer
Answer:-A. \tQ 18. What is the numerical value of the Unicode character \u0000?
A. 1
B. 0
C. 65
D. 255
Show Answer
Answer:-B. 0Q 19. Which of these operators can be used with boolean variables?
A. +
B. *
C. &
D. <<
Show Answer
Answer:-C. &Q 20. Can you perform arithmetic operations on a char variable?
A. Yes, because it is treated as an unsigned 16-bit integer.
B. No, it is purely for text.
C. Yes, but only with other char variables.
D. No, Java throws a ClassCastException.
Show Answer
Answer:-A. Yes, because it is treated as an unsigned 16-bit integer.Q 21. What is the output of: System.out.println('A' + 1);?
A. B
B. A1
C. 66
D. Compilation Error
Show Answer
Answer:-C. 66Q 22. Which of these is a valid boolean literal?
A. TRUE
B. 0
C. false
D. (boolean)1
Show Answer
Answer:-C. falseQ 23. What is the result of true && false?
A. true
B. false
C. null
D. 1
Show Answer
Answer:-B. falseQ 24. How do you represent the single quote character as a char literal?
A. '''
B. '\''
C. "'"
D. \quote
Show Answer
Answer:-B. ‘\”Q 25. If char c = 'A';, what does (int)c return?
A. 1
B. 0
C. 65
D. 97
Show Answer
Answer:-C. 65Q 26. What is the size of a boolean in Java?
A. Exactly 1 bit.
B. Exactly 8 bits.
C. It is virtual machine dependent (not precisely defined).
D. 16 bits.
Show Answer
Answer:-C. It is virtual machine dependent (not precisely defined).Q 27. Which of the following is NOT a valid char?
A. char c = '\u0041';
B. char c = 0xbeef;
C. char c = -1;
D. char c = '\n';
Show Answer
Answer:-C. char c = -1;Q 28. What is the output of System.out.println(10 > 9);?
A. 1
B. true
C. false
D. 10 > 9
Show Answer
Answer:-B. trueQ 29. Can a boolean be cast to an int in Java?
A. Yes, true becomes 1.
B. Yes, but only explicitly: (int)true.
C. No, boolean and int are incompatible types.
D. Only in Java 8 and above.
Show Answer
Answer:-C. No, boolean and int are incompatible types.Q 30. What is the wrapper class for char and boolean respectively?
A. Char, Bool
B. Character, Boolean
C. String, Boolean
D. character, boolean


Leave a Reply