Java Online Test - Data Types

Here are 10 multiple-choice questions (MCQs) based on Java data types. Each question includes options and after test submission, you can check out explanation for the correct answer. 

1. Which data type would you use to store a person's age in Java?

a) int
b) double
c) boolean
d) String

2. What is the default value of a variable of type double in Java?

a) 0
b) 0.0
c) null
d) Not set

3. Which data type can only hold the values true or false?

a) int
b) char
c) boolean
d) byte

4. What is the size of the char data type in Java?

a) 1 byte
b) 2 bytes
c) 4 bytes
d) 8 bytes

5. What is the range of the byte data type in Java?

a) -128 to 127
b) 0 to 255
c) -32768 to 32767
d) -2147483648 to 2147483647

6. Which of the following is not a primitive data type in Java?

a) int
b) String
c) float
d) short

7. Which data type is used for precise calculations involving currency?

a) int
b) double
c) float
d) BigDecimal

8. What is the size of the float data type in Java?

a) 4 bytes
b) 8 bytes
c) 2 bytes
d) 16 bytes

9. What data type would be best for storing a book's ISBN number?

a) int
b) long
c) String
d) float

10. Which Java data type would be used to store the result of comparing two integers?

a) int
b) double
c) boolean
d) long

Comments