wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

S4_Java Basics Quiz

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is the purpose of using objects as parameters in methods?

a)

To enforce data encapsulation

b)

To reduce memory usage

c)

To allow methods to modify the original object

d)

To increase the method's execution speed

2.

What does 'Call by Value' mean in Java?

a)

Passing the reference of the variable

b)

Passing a copy of the variable's value

c)

Passing the variable itself

d)

Passing the variable's address

3.

Which keyword is used to declare a constant in Java?

a)

static

b)

immutable

c)

final

d)

const

4.

What is method overloading?

a)

Defining multiple methods with the same name but different parameters

b)

Creating a method that calls itself

c)

Changing the return type of a method

d)

Using a method from a parent class

5.

What is the main concept of inheritance in Java?

a)

Preventing method overriding

b)

Combining multiple classes into one

c)

Hiding data from other classes

d)

Creating new classes from existing classes

6.

What is the purpose of the 'super' keyword in Java?

a)

To call a method from the current class

b)

To access a method from the parent class

c)

To create a new instance of a class

d)

To define a constant value

7.

What is encapsulation in object-oriented programming?

a)

Creating multiple instances of a class

b)

Inheriting properties from a parent class

c)

Overriding methods in subclasses

d)

Hiding the internal state of an object

8.

What does the 'this' keyword refer to in Java?

a)

A local variable

b)

The parent class

c)

The current object instance

d)

A static method

9.

What is polymorphism in Java?

a)

The ability to hide data within a class

b)

The ability to inherit properties from multiple classes

c)

The ability to create multiple classes

d)

The ability to call the same method on different objects

10.

What does the 'static' keyword indicate in Java?

a)

It is used to define an abstract class

b)

It is a method that cannot be overridden

c)

It can only be accessed within the same class

d)

It belongs to the class rather than instances of the class

11.

What is the purpose of the 'final' keyword when applied to a method?

a)

To prevent the method from being overridden

b)

To define a method that can be inherited

c)

To indicate that the method is abstract

d)

To allow the method to be static

12.

What is the role of the 'abstract' keyword in Java?

a)

To define a method that cannot be instantiated

b)

To indicate that a method must be implemented in a subclass

c)

To create a class that cannot be subclassed

d)

To allow multiple inheritance

13.

What is the significance of the 'interface' keyword in Java?

a)

To define a class that cannot be instantiated

b)

To define a class with static methods only

c)

To allow for method overloading

d)

To create a contract that implementing classes must follow

14.

What does the 'volatile' keyword indicate in Java?

a)

That a variable is static

b)

That a variable is only accessible within the same class

c)

That a variable is immutable

d)

That a variable can be accessed by multiple threads

15.

What is the purpose of the 'protected' access modifier in Java?

a)

To allow access to subclasses and classes in the same package

b)

To allow access from any class

c)

To allow access only within the same package

d)

To restrict access to the class itself

16.

What is the difference between '== 'and 'equals()' in Java?

a)

There is no difference; they are interchangeable

b)

'==' is used for primitive types, while 'equals()' is used for objects

c)

'==' compares object references, while 'equals()' compares object values

d)

'==' is faster than 'equals()'

17.

What is the purpose of the 'instanceof' operator in Java?

a)

To compare two objects

b)

To cast an object to a specific type

c)

To create a new instance of a class

d)

To check if an object is an instance of a specific class or interface

18.

What is the purpose of the 'abstract' class in Java?

a)

To prevent inheritance from the class

b)

To provide a base for other classes to extend

c)

To define a class with only static methods

d)

To create instances of the class

19.

What is the role of the 'throws' keyword in Java?

a)

To declare that a method can throw exceptions

b)

To define a method that cannot throw exceptions

c)

To create a new exception type

d)

To catch exceptions in a method

20.

What is the purpose of the 'default' keyword in an interface in Java?

a)

To define a method that must be implemented by all implementing classes

b)

To provide a default implementation of a method in an interface

c)

To indicate that a method is static

d)

To prevent method overriding in subclasses