NEW
Font size
WorksheetsIPS_Quiz2_Chapter2
Total questions: 13
Worksheet time: 7mins
Which of the following is a valid variable declaration in Java?
int 1stNumber = 10;
double rate = 5.5;
String name = 'John';
boolean flag = "true"
Which data type is used to store a single character in Java?
char
String
byte
boolean
Which of these is a correct way to declare a constant in Java?
final int SPEED = 60;
const int SPEED = 60;
static int SPEED = 60;
immutable int SPEED = 60;
What will be the result of the following code? int x = 5; int y = 2; double result = x / y; System.out.println(result);
A. 2
B. 2.0
C. 2.5
D. Compilation error
Which data type has the largest range of values?
int
long
float
double
Which of the following variable names is NOT valid in Java?
_count
$salary
total#amount
firstName
What keyword is used to create a variable that cannot be reassigned?
final
const
static
constant
Which of the following will correctly print the ASCII value of character 'A'?
System.out.println((int)'A');
System.out.println("A".getASCII());
System.out.println(int('A'));
System.out.println(ascii('A'));
Which of the following is a valid declaration for a float variable in Java? Choose the correct option.
float rate = 5.5;
float rate = '5.5';
float rate = "5.5";
float rate = 5,5;
Which of the following is the correct way to declare a constant integer value in Java? Choose the correct option.
final int SPEED = 60;
const int SPEED = 60;
What is the result of the following Java expression? double d = 2 / 2; Choose the correct option.
1.0
2.0
1
2
Which Java primitive type has a larger range than long or float? Choose the correct option.
int
double
short
byte
Which keyword in Java prevents reassignment of variables? Choose the correct option.
final
static
const
private
