wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Core Java Concepts Quiz (1)

Total questions: 48

Worksheet time: 25mins

Name
Class
Date
1.

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

a)

String

b)

class

c)

int

d)

Object

2.

Which data type is used to store true or false values?

a)

char

b)

boolean

c)

double

d)

byte

3.

What is the purpose of declaring a variable in Java?

a)

To define a class.

b)

To allocate memory to store data.

c)

To create a new method.

d)

To print output to the console.

4.

Which operator is used for equality comparison in Java?

a)

=

b)

==

c)

!=

d)

>

5.

What is the result of the expression 5 % 2?

a)

2.5

b)

1

c)

0

d)

7

6.

Which of the following is a logical AND operator in Java?

a)

|

b)

&

c)

||

d)

&&

7.

Which keyword is used to start an if statement in Java?

a)

when

b)

if

c)

condition

d)

check

8.

Which loop in Java guarantees that the code block will execute at least once?

a)

for loop

b)

while loop

c)

do-while loop

d)

if-else statement

9.

What is the purpose of the break statement within a loop?

a)

To skip the current iteration and continue to the next.

b)

To terminate the loop immediately.

c)

To execute the loop in reverse order.

d)

To define the loop's condition.

10.

How do you declare an array of integers named numbers that can hold 5 elements?

a)

int numbers = new array[5];

b)

array numbers = new int(5);

c)

int[] numbers = new int[5];

d)

int numbers[5] = new int[];

11.

What is the index of the first element in an array in Java?

a)

1

b)

0

c)

The size of the array

d)

-1

12.

How do you access the element at index 2 in an array named data?

a)

data(2)

b)

data[2]

c)

data.get(2)

d)

data.element(2)

13.

What is a class in Java?

a)

An instance of an object.

b)

A blueprint for creating objects.

c)

A primitive data type.

d)

A method that belongs to an object.

14.

What is an object in Java?

a)

A definition of attributes and behaviors.

b)

A keyword used to define a class.

c)

An instance of a class.

d)

A collection of related classes.

15.

What is encapsulation in OOP?

a)

The ability of an object to take on many forms.

b)

The mechanism of deriving a new class from an existing one.

c)

Bundling data and methods that operate on the data within a single unit.

d)

The process of hiding the implementation details of an object.

16.

What is inheritance in OOP?

a)

The ability of an object to take on many forms.

b)

The mechanism of deriving a new class from an existing one.

c)

Bundling data and methods that operate on the data within a single unit.

d)

The process of hiding the implementation details of an object.

17.

What is polymorphism in OOP?

a)

The ability of an object to take on many forms.

b)

The mechanism of deriving a new class from an existing one.

c)

Bundling data and methods that operate on the data within a single unit.

d)

The process of hiding the implementation details of an object.

18.

What is the purpose of a method in Java?

a)

To define the data types of variables.

b)

To declare a new class.

c)

To perform a specific task or operation.

d)

To handle errors during program execution.

19.

Which keyword is used to define a method in Java?

a)

function

b)

method

c)

void (sometimes, but not always the defining keyword)

d)

The method name followed by parentheses ()

20.

What are parameters in a method?

a)

The return value of the method.

b)

Variables that receive values when the method is called.

c)

Keywords used to define the method's access level.

d)

The name of the method.

21.

Which class is commonly used to get input from the user in Java?

a)

System

b)

PrintStream

c)

Scanner

d)

InputStream

22.

Which method of the System.out object is used to print output to the console without a newline character at the end?

a)

println()

b)

print()

c)

printf()

d)

format()

23.

What is an exception in Java?

a)

A normal event during program execution.

b)

An error that occurs during the compilation phase.

c)

An event that disrupts the normal flow of the program.

d)

A reserved keyword in Java.

24.

Which block is used to enclose code that might throw an exception?

a)

catch

b)

finally

c)

try

d)

throw

25.

Which block is used to handle an exception that has occurred?

a)

try

b)

finally

c)

catch

d)

throws

26.

Which of the following primitive data types in Java is used to store single characters?

a)

String

b)

char

c)

byte

d)

short

27.

What is the size in bits of the int primitive data type in Java?

a)

8 bits

b)

16 bits

c)

32 bits

d)

64 bits

28.

Which primitive data type is used to store whole numbers without decimal points and typically occupies the least amount of memory?

a)

int

b)

long

c)

short

d)

byte

29.

Which primitive data type is used to store floating-point numbers with single-precision?

a)

double

b)

float

c)

long

d)

decimal

30.

Which primitive data type is used to store large whole numbers that might exceed the range of an int?

a)

short

b)

byte

c)

long

d)

float

31.

What is the default value of a boolean primitive data type if it's declared as an instance variable (member of a class) but not explicitly initialized?

a)

true

b)

false

c)

null

d)

0

32.

What is the range of values that a byte primitive data type can hold in Java?

a)

0 to 255

b)

-128 to 127

c)

-32768 to 32767

d)

Approximately -2 billion to +2 billion

33.

Which of the following is a valid literal for a char primitive data type?

a)

'abc'

b)

"a"

c)

'a'

d)

a

34.

What happens if you try to store a value larger than the maximum range of an int into an int variable without explicit casting?

a)

The program will throw a runtime exception.

b)

The value will be automatically rounded.

c)

The value will overflow, potentially leading to unexpected results (e.g., wrapping around to negative values).

d)

The compiler will issue an error.

35.

Which primitive data type in Java is 64 bits and designed for more precise floating-point calculations?

a)

float

b)

long

c)

double

d)

BigDouble

36.
Which type of data is used to enter the value ("Welcome")?
a)
Text
b)
Characters
c)
String
d)
Boolean
37.

Which primitive type is for integers?

a)

boolean

b)

char

c)

double

d)

long

38.

Which of the following is NOT a Java primitive type

a)

double

b)

float

c)

int

d)

String

39.

What is each repetition of a loop known as?

a)

cycle

b)

revlolution

c)

orbit

d)

iteration

40.

Which statement(s) are equivalent to i = i + 1?

a)

i += 1

b)

i++

c)

i -= 1

d)

i--

41.

Which primitive data type represents an 8-bit signed integer?

a)

short

b)

int

c)

byte

d)

char

42.

Which primitive data type represents a 64-bit floating-point number?

a)

float

b)

double

c)

long

d)

int

43.

Which primitive data type represents a 16-bit Unicode character?

a)

short

b)

char

c)

boolean

d)

byte

44.

Which primitive data type represents a logical value?

a)

int

b)

float

c)

boolean

d)

String

45.

Which primitive data type represents a 32-bit signed integer?

a)

long

b)

int

c)

short

d)

byte

46.

Which primitive data type represents a 64-bit signed integer?

a)

long

b)

int

c)

short

d)

byte

47.

Which primitive data type represents a 32-bit single-precision floating-point number?

a)

double

b)

float

c)

long

d)

int

48.

Which data type can hold the value true or false?

a)

char

b)

int

c)

boolean

d)

String