Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Fundamentals Assessment

Total questions: 20

Worksheet time: 7mins

Name
Class
Date
1.

What is the main purpose of Java?

a)

To develop operating systems

b)

The main purpose of Java is to enable platform-independent application development.

c)

To create web browsers

d)

To enhance hardware performance

2.

What is the syntax to declare a variable in Java?

a)

variableName dataType;

b)

dataType = variableName;

c)

var variableName: dataType;

d)

dataType variableName;

3.

What are the primitive data types in Java?

a)

string

b)

array

c)

object

d)

byte, short, int, long, float, double, char, boolean

4.

How do you create a constant variable in Java?

a)

Use 'static' to create a constant variable in Java.

b)

Declare a variable without any keyword to make it constant.

c)

Use the 'final' keyword to declare a constant variable, e.g., 'final int MY_CONSTANT = 10;'.

d)

Use the 'const' keyword to declare a constant variable.

5.

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

a)

'==' is for reference comparison, while '.equals()' is for value comparison.

b)

Both '==' and '.equals()' are used for reference comparison.

c)

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

d)

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

6.

What is a control structure in Java?

a)

A control structure in Java is a construct that controls the flow of execution in a program.

b)

A control structure in Java is a type of variable.

c)

A control structure in Java is a method for defining classes.

d)

A control structure in Java is a way to declare constants.

7.

How do you create a loop in Java?

a)

Java does not support looping constructs.

b)

You can create a loop in Java using 'switch' statements.

c)

Loops in Java can only be created with 'if' statements.

d)

You can create a loop in Java using 'for', 'while', or 'do-while' statements.

8.

What is the syntax for a 'for' loop in Java?

a)

for(condition; initialization; increment/decrement) { // loop body }

b)

for(initialization; increment/decrement; condition) { // loop body }

c)

for(initialization; condition; increment/decrement) { // loop body }

d)

for(initialization; condition) { // loop body }

9.

What is Object-Oriented Programming (OOP)?

a)

A method for writing procedural code

b)

A way to create static websites

c)

A programming language that only uses functions

d)

Object-Oriented Programming (OOP) is a programming paradigm that uses 'objects' to design applications.

10.

How do you define a class in Java?

a)

define a class using 'define ClassName() {}'

b)

class ClassName: // fields and methods

c)

class ClassName { // fields and methods }

d)

class ClassName { fields; methods; }

11.

What is an object in Java?

a)

An object is a method that performs actions.

b)

A class is a blueprint for creating objects.

c)

An object is a static data type in Java.

d)

An object in Java is an instance of a class that contains state and behavior.

12.

What are the four main principles of OOP?

a)

Encapsulation, Abstraction, Inheritance, Polymorphism

b)

Composition

c)

Aggregation

d)

Interface

13.

What is inheritance in Java?

a)

Inheritance is a method to delete properties from a class.

b)

Inheritance allows a class to create new classes without any properties.

c)

Inheritance in Java is a way to define multiple classes with the same name.

d)

Inheritance in Java allows a class to inherit properties and behaviors (methods) from another class.

14.

What is polymorphism in Java?

a)

Polymorphism is the ability to create multiple classes in Java.

b)

Polymorphism refers to the process of compiling Java code.

c)

Polymorphism is a method of optimizing Java performance.

d)

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

15.

What is encapsulation in Java?

a)

Encapsulation is the process of converting Java code into machine code.

b)

Encapsulation refers to the use of multiple inheritance in Java.

c)

Encapsulation is the method of optimizing Java code for performance.

d)

Encapsulation is the bundling of data and methods that operate on that data, restricting access to some components.

16.

What is an interface in Java?

a)

An interface in Java is a reference type that defines a contract of methods for classes to implement.

b)

A class that implements multiple methods

c)

A type of variable that holds data

d)

A collection of objects that can be instantiated

17.

How do you implement an interface in a class?

a)

class ClassName uses InterfaceName { /* method implementations */ }

b)

class ClassName implements InterfaceName { /* method implementations */ }

c)

class ClassName extends InterfaceName { /* method implementations */ }

d)

class ClassName implements InterfaceName() { /* method implementations */ }

18.

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

a)

The 'this' keyword is used to define static methods.

b)

The 'this' keyword refers to the parent class instance.

c)

The 'this' keyword refers to the current instance of a class.

d)

The 'this' keyword is used for declaring global variables.

19.

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

a)

The 'super' keyword is used to define static variables.

b)

The 'super' keyword is used to create new instances of a class.

c)

The 'super' keyword is used to call the parent class constructor.

d)

The 'super' keyword is used to access private methods of the parent class.

20.

What is the difference between 'abstract class' and 'interface' in Java?

a)

There is no difference; they are the same in Java.

b)

Both abstract classes and interfaces can have constructors.

c)

An abstract class can have both abstract and concrete methods, while an interface can only have abstract methods.

d)

Abstract classes cannot be instantiated, while interfaces can.