wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Fundamentals Challenge

Total questions: 53

Worksheet time: 28mins

Name
Class
Date
1.

What is the main principle of Object-Oriented Programming?

a)

Data encapsulation only

b)

Single inheritance only

c)

Encapsulation, inheritance, polymorphism, and abstraction.

d)

Static typing only

2.

Which of the following is not a Java data type?

a)

integer

b)

float

c)

boolean

d)

string

3.

What keyword is used to create a class in Java?

a)

class

b)

function

c)

create

d)

define

4.

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

a)

-1

b)

1

c)

0

d)

null

5.

Which control structure is used to execute a block of code repeatedly?

a)

Loop

b)

Function

c)

Variable

d)

Condition

6.

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

a)

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

b)

To define a function in Python.

c)

To declare variables in a program.

d)

To optimize code performance.

7.

What is inheritance in the context of Object-Oriented Programming?

a)

Inheritance allows a subclass to inherit attributes and methods from a superclass, enabling code reuse and establishing a class hierarchy.

b)

Inheritance is a method for creating new classes without any relationship to existing ones.

c)

Inheritance is the process of deleting attributes from a class.

d)

Inheritance allows a class to operate independently without any parent class.

8.

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

a)

int[] numbers;

b)

int numbers = new int();

c)

int numbers[];

d)

array numbers int;

9.

What is the result of the expression 5 / 2 in Java?

a)

2.5

b)

1.5

c)

2

d)

3

10.

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

a)

The 'catch' block is meant to optimize code performance.

b)

The 'catch' block is for logging errors only.

c)

The purpose of the 'catch' block is to handle exceptions and prevent program termination.

d)

The 'catch' block is used to define new exceptions.

11.

What is polymorphism in Java?

a)

Polymorphism refers to the process of compiling Java code into bytecode.

b)

Polymorphism is the ability to create multiple classes in Java.

c)

Polymorphism is the ability to change the data type of a variable at runtime.

d)

Polymorphism is the ability of a single function or method to operate in different ways based on the object it is acting upon.

12.

Which control structure allows for a choice between multiple options?

a)

if statement

b)

for loop

c)

switch statement

d)

while loop

13.

What is the difference between checked and unchecked exceptions?

a)

Both checked and unchecked exceptions require handling.

b)

Unchecked exceptions must be declared in the method signature.

c)

Checked exceptions are always runtime errors.

d)

Checked exceptions require handling, while unchecked exceptions do not.

14.

What is the keyword used to inherit a class in Java?

a)

derives

b)

inherits

c)

implements

d)

extends

15.

What is the output of the following code: System.out.println(3 + 4 + "5");?

a)

34

b)

75.0

c)

8

d)

75

16.

What is encapsulation in Object-Oriented Programming?

a)

Encapsulation is the process of creating multiple instances of a class.

b)

Encapsulation refers to the inheritance of properties from a parent class.

c)

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

d)

Encapsulation is the method of exposing all data and methods of an object to the outside world.

17.

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

a)

To execute code regardless of whether an exception was thrown or not.

b)

To catch specific exceptions only.

c)

To define a new exception type.

d)

To optimize the performance of the program.

18.

Which of the following keywords is used to create an interface in Java?

a)

extends

b)

interface

c)

implements

d)

class

19.

What is the output of the following code: System.out.println("Hello" + 5 + 10);?

a)

Hello15

b)

Hello510

c)

15Hello

d)

Hello 5 10

20.

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

a)

To define a new variable.

b)

To implement an interface.

c)

To create a new instance of a class.

d)

To call a method from the parent class.

21.

Which of the following is a valid way to create a string in Java?

a)

String str = new String();

b)

String str = new String("Hello");

c)

String str = "Hello";

d)

String str = String();

22.

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

a)

The static context of the class.

b)

The method being executed.

c)

The parent class instance.

d)

The current object instance.

23.

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

a)

To create a new instance of a class.

b)

To define a method that must be implemented by subclasses.

c)

To declare a variable that cannot be changed.

d)

To inherit properties from a parent class.

24.

What is the result of the expression "Hello" + 3 + 4 in Java?

a)

Hello 3 4

b)

Hello34

c)

Hello7

d)

7Hello

25.

Which of the following statements is true about interfaces in Java?

a)

Interfaces can only contain abstract methods.

b)

Interfaces cannot be implemented by classes.

c)

Interfaces can extend multiple classes.

d)

Interfaces can contain method implementations.

26.

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

a)

To define a method that can be called without creating an instance of the class.

b)

To inherit properties from a parent class.

c)

To create a new instance of a class.

d)

To declare a variable that cannot be changed.

27.

What is method overloading in Java?

a)

Creating a method that overrides a parent class method.

b)

Defining a method that cannot be overridden.

c)

Defining multiple methods with the same name but different parameters.

d)

Creating a method that is private to the class.

28.

What is the output of the following code: System.out.println(10 % 3);?

a)

10

b)

0

c)

1

d)

3

29.

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

a)

To declare a variable that cannot be changed.

b)

To define a method that must be implemented by subclasses.

c)

To ensure that a variable is always read from main memory.

d)

To create a new instance of a class.

30.

What will be the output of the following code: System.out.println(5 + "5");?

a)

10

b)

55

c)

5 5

d)

5

31.

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

a)

To define a method that can be called without creating an instance of the class.

b)

To restrict access to a method or block to a single thread.

c)

To allow multiple threads to access a method simultaneously.

d)

To declare a variable that cannot be changed.

32.

Which of the following statements about abstract classes in Java is true?

a)

Abstract classes can be instantiated directly.

b)

Abstract classes can contain both abstract and concrete methods.

c)

Abstract classes cannot have constructors.

d)

Abstract classes cannot have any fields.

33.

What is the output of the following code: System.out.println(10 % 3);?

a)

3

b)

1

c)

0

d)

10

34.

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

a)

public myMethod() {}

b)

myMethod void() {}

c)

void myMethod public() {}

d)

public void myMethod() {}

35.

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

a)

To create a new instance of a class.

b)

To declare a variable that can be changed.

c)

To define a method that can be overridden.

d)

To prevent a class from being subclassed.

36.

Which of the following statements about constructors in Java is true?

a)

A constructor can have a return type.

b)

A constructor is called when an object is created.

c)

A constructor must be defined in every class.

d)

A constructor can be private only.

37.

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

a)

It is used to declare an interface.

b)

It is used to call the parent class constructor.

c)

It is used to create a new instance of a class.

d)

It is used to define a static method.

38.

What is the output of the following code: System.out.println(7 - 2 + "3");?

a)

5 3

b)

73

c)

5

d)

53

39.

What does the 'static' keyword indicate in Java?

a)

It allows a method to be called without creating an instance of the class.

b)

It restricts the visibility of a method to the class itself.

c)

It indicates that a variable can be changed at runtime.

d)

It is used to define a method that can be overridden.

40.

What is the result of the expression "10" + 5 * 2 in Java?

a)

105

b)

10

c)

15

d)

20

41.

What is the output of the following code: System.out.println("Java" + " is fun!");?

a)

Javaisfun!

b)

is fun!Java

c)

Java isfun!

d)

Java is fun!

42.

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

a)

int arr[5];

b)

int arr = new int[];

c)

int arr[] = int[5];

d)

int[] arr = new int[5];

43.

What does the 'volatile' keyword indicate in Java?

a)

It indicates that a variable can be accessed by multiple threads.

b)

It is used to define a method that cannot be overridden.

c)

It restricts the visibility of a variable to the class itself.

d)

It allows a variable to be changed at runtime.

44.

Which of the following keywords is used to define a constant variable in Java?

a)

static

b)

const

c)

final

d)

constant

45.

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

a)

4

b)

5

c)

3

d)

6

46.

Which of the following is a valid way to create a new thread in Java?

a)

Thread t = new Thread(new Runnable());

b)

All of the above

c)

Thread t = new Thread();

d)

Thread t = new Thread(() -> {});

47.

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

a)

Hello World

b)

Error

c)

HelloWorld

d)

"Hello" + " World"

48.

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

a)

class MyClass extends MyInterface {}

b)

class MyClass uses MyInterface {}

c)

class MyClass inherits MyInterface {}

d)

class MyClass implements MyInterface {}

49.

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

a)

All of the above

b)

To create a constant value.

c)

To define a method that cannot be overridden.

d)

To declare a variable that cannot be changed.

50.

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

a)

new ClassName obj = ClassName();

b)

ClassName obj = ClassName();

c)

ClassName obj = create ClassName();

d)

ClassName obj = new ClassName();

51.

Hall_Ticket_Number

(a)  

52.

Gender

(a)  

53.

College/Branch

(a)