wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

IPS_Quiz2_Chapter2

Total questions: 13

Worksheet time: 7mins

Name
Class
Date
1.

Which of the following is a valid variable declaration in Java?

a)

int 1stNumber = 10;

b)

double rate = 5.5;

c)

String name = 'John';

d)

boolean flag = "true"

2.

Which data type is used to store a single character in Java?

a)

char

b)

String

c)

byte

d)

boolean

3.

Which of these is a correct way to declare a constant in Java?

a)

final int SPEED = 60;

b)

const int SPEED = 60;

c)

static int SPEED = 60;

d)

immutable int SPEED = 60;

4.

What will be the result of the following code? int x = 5; int y = 2; double result = x / y; System.out.println(result);

a)

A. 2

b)

B. 2.0

c)

C. 2.5

d)

D. Compilation error

5.

Which data type has the largest range of values?

a)

int

b)

long

c)

float

d)

double

6.

Which of the following variable names is NOT valid in Java?

a)

_count

b)

$salary

c)

total#amount

d)

firstName

7.

What keyword is used to create a variable that cannot be reassigned?

a)

final

b)

const

c)

static

d)

constant

8.

Which of the following will correctly print the ASCII value of character 'A'?

a)

System.out.println((int)'A');

b)

System.out.println("A".getASCII());

c)

System.out.println(int('A'));

d)

System.out.println(ascii('A'));

9.

Which of the following is a valid declaration for a float variable in Java? Choose the correct option.

a)

float rate = 5.5;

b)

float rate = '5.5';

c)

float rate = "5.5";

d)

float rate = 5,5;

10.

Which of the following is the correct way to declare a constant integer value in Java? Choose the correct option.

a)

final int SPEED = 60;

b)

const int SPEED = 60;

11.

What is the result of the following Java expression? double d = 2 / 2; Choose the correct option.

a)

1.0

b)

2.0

c)

1

d)

2

12.

Which Java primitive type has a larger range than long or float? Choose the correct option.

a)

int

b)

double

c)

short

d)

byte

13.

Which keyword in Java prevents reassignment of variables? Choose the correct option.

a)

final

b)

static

c)

const

d)

private