wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Mastering Java Fundamentals

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What is the correct way to declare a variable in Java?

a)

int variableName;

b)

string variableName;

c)

var variableName;

d)

float variableName = 5;

2.

Which of the following is a valid Java data type?

a)

string

b)

boolean

c)

int

d)

float

3.

What does OOP stand for in programming?

a)

Object-Oriented Programming

b)

Operational Object Programming

c)

Open Object Protocol

d)

Object-Optimized Programming

4.

Which keyword is used to create a class in Java?

a)

class

b)

define

c)

function

d)

create

5.

How do you handle exceptions in Java?

a)

Use if-else statements to handle exceptions in Java.

b)

Throw exceptions without handling them.

c)

Ignore exceptions and continue execution.

d)

Use try-catch blocks to handle exceptions in Java.

6.

What is the purpose of the 'try' block in exception handling?

a)

The 'try' block is used to optimize code performance.

b)

The 'try' block is for declaring variables only.

c)

The purpose of the 'try' block is to catch exceptions that may occur during the execution of code.

d)

The 'try' block is used to define functions in Python.

7.

What is inheritance in the context of OOP?

a)

Inheritance is a method for encapsulating data within a class.

b)

Inheritance is a way to create multiple instances of a class.

c)

Inheritance is a mechanism in OOP where a class can inherit attributes and methods from another class.

d)

Inheritance allows classes to be combined into one.

8.

Which method is called when an exception is caught?

a)

finally block

b)

catch block

c)

throw statement

d)

try block

9.

What is the default value of an uninitialized int variable in Java?

a)

undefined

b)

-1

c)

0

d)

null

10.

What is polymorphism in Java?

a)

Polymorphism is a method of data encryption in Java.

b)

Polymorphism refers to the process of converting data types into one another.

c)

Polymorphism is the ability to create multiple classes with the same name.

d)

Polymorphism is the ability of a single interface to represent different underlying forms (data types).