wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Java Programming Quiz

Total questions: 10

Worksheet time: 15mins

Name
Class
Date
1.

Which of the following is NOT one of the four main principles of Object-Oriented Programming (OOP) in Java?

a)

Polymorphism

b)

Abstraction

c)

Decapsulation

d)

Encapsulation

2.

What is the minimum size, in bits, and the keyword used to declare the largest integer primitive data type in Java?

a)

32 bits, int

b)

64 bits, long

c)

16 bits, short

d)

8 bits, byte

3.

Which statement is true regarding variable scope and lifetime in Java?

a)

Variables hold their values once they go out of scope.

b)

A block defines a scope.

c)

Variables declared in an inner scope are visible outside of it.

d)

Variables declared within a method hold their values between calls to that method.

4.

In the Java expression a += 5;, which of the following is the equivalent long form of the statement?

a)

a * 5

b)

a = a + 5

c)

a = 5

d)

a + 5

5.

What is the defining characteristic of the do-while loop compared to the while loop?

a)

It executes only if the condition is false.

b)

It always executes its body at least once.

c)

Its condition is at the top of the loop.

d)

It must be initialized using the for keyword.

6.

Which statement correctly describes the function of the break statement within a switch?

a)

It causes execution to continue to the next case.

b)

It is optional, and if omitted, the code following the switch statement is executed.

c)

It terminates the statement sequence and branches execution to the first line of code following the entire switch statement.

d)

It immediately terminates the method in which it is executed.

7.

What is the outcome of using the short-circuit logical AND operator (&&) when the left-hand operand evaluates to false?

a)

The right-hand operand is evaluated, and the result is true.

b)

The right-hand operand is evaluated, and the result is false.

c)

The right-hand operand is not evaluated, and the result is false.

d)

The right-hand operand is not evaluated, and the result is true.

8.

What is a class mainly used for in Java programming?

a)

To store a single simple data value like a number.

b)

To define a new complex data type and serve as a blueprint for creating objects.

c)

To hold a fixed list of same-typed variables.

d)

To automatically deallocate memory from unused objects.

9.

What are the two components (members) that are typically defined inside a class?

a)

Keywords and Operators.

b)

Integers and Booleans.

c)

Instance variables and Methods

d)

Conditions and Iterations.

10.

What is the purpose of the this keyword when used inside a method of a class?

a)

It is used to declare a new local variable.

b)

It acts as a reference to the calling routine.

c)

It refers to the current object that invoked the method.

d)

It explicitly forces garbage collection.