Font size
WorksheetsCh 02B: Variables & Data Types
Total questions: 16
Worksheet time: 10mins
Which of the following is NOT a primitive data type in Java?
int
String
boolean
double
What is the default value of a Java `int` variable that is declared as a class member but not initialized?
0
null
false
undefined
Which keyword is used to declare a constant variable in Java?
static
final
const
constant
Which of the following is the correct syntax to declare a variable of type `double` in Java?
double value;
Double value;
double = value;
value double;
Which primitive data type would you use to store a single Unicode character in Java?
char
byte
String
boolean
Which of the following statements correctly casts an `int` variable named `num` to a `double` in Java?
double num = (double) num;
double num = double(num);
double num = num.toDouble();
double num = (int) num;
Which of the following code snippets will result in a compilation error due to type incompatibility?
int a = 5.5;
double b = 5;
char c = 'A';
boolean d = true;
What will be the output of the following code? ```java final int MAX = 100; MAX = 200; System.out.println(MAX); ```
100
200
Compilation error
0
Given the following code, what will be printed? ```java int a = 5; double b = a / 2; System.out.println(b); ```
2.5
2.0
2
2.00
Consider the following code: ```java public class Test { public static void main(String[] args) { int x = 10; { int x = 20; System.out.println(x); } System.out.println(x); } } ``` What will happen when you try to compile and run this code?
It prints 20 and then 10
It prints 10 and then 20
Compilation error due to variable redeclaration
It prints 20 twice
Suppose you want to declare a constant for the value of π in Java. Which of the following is the best way to do it?
final double pi = 3.14159;
double pi = 3.14159;
const double pi = 3.14159;
static double pi = 3.14159;
What is the value stored in x?
double x = (int) (1.8 * 2.0)
3.0
3
3.6
Error
What is the resulting value of
(int)23.5
24
23
23.5
trick question, it's an error
Match the following
5
5.2
'a'
"abc"
true
Which of the following is NOT a numeric data type
int
double
float
decimal
