Java MCQ Questions - Variables, Data Types, and Operators
1. Which of the following is a valid variable declaration in Java?
a) int 1num
b) float my num
c) double salary
d) char = 'A'
2. What is the default value of a boolean variable in Java (for instance variables)?
a) true
b) false
c) 0
d) null
3. Which keyword is used to define a constant variable in Java?
a) finalize
b) const
c) final
d) static
4. Which of these is not a valid variable name in Java?
a) _value
b) value123
c) 123value
d) value_123
5. What is the size of int data type in Java?
a) 2 bytes
b) 4 bytes
c) 8 bytes
d) Depends on OS
6. Which of these is NOT a primitive data type in Java?
a) int
b) boolean
c) String
d) double
7. What is the range of byte in Java?
a) -128 to 127
b) 0 to 255
c) -32768 to 32767
d) -255 to 255
8. Which data type is used to store Unicode characters in Java?
a) String
b) char
c) Character
d) int
9. What is the output of this expression: 5 + 2 * 3?
a) 21
b) 15
c) 11
d) 7
10. Which of these is a logical operator in Java?
a) ==
b) =
c) &&
d) %
11. Which operator is used to compare two values in Java?
a) =
b) ==
c) !=
d) :=
12. What does the % operator do in Java?
a) Divides two numbers
b) Returns remainder
c) Converts to percentage
d) Rounds to nearest integer
13. Which of these is the correct syntax for incrementing a variable by 1?
a) x = x + 1;
b) x += 1;
c) x++;
d) All of the above