Here are 10 essential multiple-choice questions on Java Data Types, covering key concepts.
Question 2
Which data type is best for storing the ASCII value of a character?
char
byte
int
short
Question 3
What will be the output of this code?
int a = 7;
double b = 2;
System.out.println(a / b);
3
3.5
3.0
Error
Question 4
Which of the following is a valid declaration of a float data type?
float f = 10.5;
float f = 10.5f;
float f = "10.5";
float f = (10.5);
Question 5
What will be the output of this code?
byte x = 127;
x++;
System.out.println(x);
128
127
-128
Compilation Error
Question 6
Which of the following combinations will NOT compile?
long l = 100L;
int i = 10000000000;
double d = 1.2e3;
short s = 100;
Question 7
What is the size of the char type in Java?
8 bits
32 bits
16 bits
Depends on the platform
Question 8
What will be printed by the following code?
float f = 5.6f;
int i = (int) f;
System.out.println(i);
Compilation Error
5.6
6
5
Question 9
What is the result of this code?
int a = 1_000_000;
float b = a;
System.out.println(b == a);
true
false
Compilation Error
Runtime Error
Question 10
What will be the output of the following code?
long l = 2147483648L;
int i = (int) l;
System.out.println(i);
2147483648
-2147483648
Overflow
Compilation Error
There are 10 questions to complete.