wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Java Programming Quiz

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

What is the primary feature of Java that allows code to run on any device that supports the JVM?

a)

Write Once, Run Anywhere

b)

Compile Once, Run Anywhere

c)

Write Once, Compile Anywhere

d)

Run Anywhere, Write Once

2.

Which of the following is NOT a core principle of Object-Oriented Programming (OOP) in Java?

a)

Inheritance

b)

Polymorphism

c)

Encapsulation

d)

Compilation

3.

What is the output of the following Java code: System.out.println("Hello World");?

a)

Hello World

b)

Hello

c)

World

d)

Error

4.

Which Java framework is commonly used for building enterprise applications?

a)

Ruby on Rails

b)

Flask

c)

Django

d)

Spring

5.

What type of method allows you to pass a variable number of arguments in Java?

a)

Varargs

b)

Abstract Method

c)

Instance Method

d)

Static Method

6.

Which of the following is a collection interface in Java?

a)

Character

b)

Integer

c)

String

d)

List

7.

What keyword is used to handle exceptions in Java?

a)

try

b)

catch

c)

All of the above

d)

throw

8.

Which of the following is used to create a thread in Java?

a)

Thread Class

b)

Both A and B

c)

Executor Service

d)

Runnable Interface

9.

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

a)

All of the above

b)

To declare constants

c)

To prevent method overriding

d)

To prevent inheritance

10.

Which of the following is a valid way to declare an array in Java?

a)

int arr[] = new int[5];

b)

int[] arr = new int[5];

c)

int arr[] = new int(5);

d)

int arr = new int[5];

11.

What is the main purpose of Java's garbage collection?

a)

To free up memory

b)

To compile code

c)

To handle exceptions

d)

To manage threads

12.

Which of the following is NOT a Java access modifier?

a)

static

b)

private

c)

protected

d)

public

13.

What does JVM stand for?

a)

Java Version Manager

b)

Java Virtual Machine

c)

Java Variable Method

d)

Java Visual Machine

14.

Which of the following is a feature of Java?

a)

Multiple Inheritance

b)

Low-level programming

c)

Platform Independence

d)

Pointer Arithmetic

15.

What is the default value of a boolean variable in Java?

a)

true

b)

false

c)

0

d)

1

16.

Which of the following is a valid way to create an instance of a class in Java?

a)

ClassName obj = ClassName.new();

b)

ClassName obj = new ClassName();

c)

ClassName obj = new ClassName;

d)

ClassName obj = ClassName();

17.

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

a)

To allow multiple threads to access a method

b)

To prevent thread interference

c)

To create a new thread

d)

To declare a method as final

18.

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

a)

To declare a static variable

b)

To call a superclass method

c)

To create a new instance

d)

To refer to the current object

19.

Which of the following is a valid way to implement an interface in Java?

a)

class MyClass MyInterface {}

b)

class MyClass extends MyInterface {}

c)

class MyClass implements MyInterface {}

d)

class MyClass implements MyInterface()

20.

What is the main advantage of using interfaces in Java?

a)

To restrict access to methods

b)

To improve performance

c)

To provide a blueprint for classes

d)

To achieve multiple inheritance

21.

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

a)

To declare abstract classes

b)

To restrict method access

c)

To define class-level methods and variables

d)

To create instance variables

22.

Which of the following is a feature of Java's exception handling?

a)

Runtime checking

b)

Compile-time checking

c)

Both A and B

d)

None of the above

23.

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

a)

To declare a static method

b)

To create a new instance of a class

c)

To refer to the superclass of the current object

d)

To call a constructor of the current class

24.

What is the main purpose of the 'volatile' keyword in Java?

a)

To ensure thread safety

b)

To declare a constant variable

c)

To create a synchronized block

d)

To prevent method overriding

25.

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

a)

To define a method without implementation

b)

To create a final class

c)

To declare a static method

d)

To implement multiple inheritance