Font size
WorksheetsJava Fundamentals Challenge
Total questions: 53
Worksheet time: 28mins
What is the main principle of Object-Oriented Programming?
Data encapsulation only
Single inheritance only
Encapsulation, inheritance, polymorphism, and abstraction.
Static typing only
Which of the following is not a Java data type?
integer
float
boolean
string
What keyword is used to create a class in Java?
class
function
create
define
What is the default value of an int variable in Java?
-1
1
0
null
Which control structure is used to execute a block of code repeatedly?
Loop
Function
Variable
Condition
What is the purpose of the 'try' block in exception handling?
The purpose of the 'try' block is to catch exceptions that may occur during code execution.
To define a function in Python.
To declare variables in a program.
To optimize code performance.
What is inheritance in the context of Object-Oriented Programming?
Inheritance allows a subclass to inherit attributes and methods from a superclass, enabling code reuse and establishing a class hierarchy.
Inheritance is a method for creating new classes without any relationship to existing ones.
Inheritance is the process of deleting attributes from a class.
Inheritance allows a class to operate independently without any parent class.
Which of the following is a valid way to declare an array in Java?
int[] numbers;
int numbers = new int();
int numbers[];
array numbers int;
What is the result of the expression 5 / 2 in Java?
2.5
1.5
2
3
What is the purpose of the 'catch' block in exception handling?
The 'catch' block is meant to optimize code performance.
The 'catch' block is for logging errors only.
The purpose of the 'catch' block is to handle exceptions and prevent program termination.
The 'catch' block is used to define new exceptions.
What is polymorphism in Java?
Polymorphism refers to the process of compiling Java code into bytecode.
Polymorphism is the ability to create multiple classes in Java.
Polymorphism is the ability to change the data type of a variable at runtime.
Polymorphism is the ability of a single function or method to operate in different ways based on the object it is acting upon.
Which control structure allows for a choice between multiple options?
if statement
for loop
switch statement
while loop
What is the difference between checked and unchecked exceptions?
Both checked and unchecked exceptions require handling.
Unchecked exceptions must be declared in the method signature.
Checked exceptions are always runtime errors.
Checked exceptions require handling, while unchecked exceptions do not.
What is the keyword used to inherit a class in Java?
derives
inherits
implements
extends
What is the output of the following code: System.out.println(3 + 4 + "5");?
34
75.0
8
75
What is encapsulation in Object-Oriented Programming?
Encapsulation is the process of creating multiple instances of a class.
Encapsulation refers to the inheritance of properties from a parent class.
Encapsulation is the bundling of data and methods that operate on that data, restricting direct access to some of the object's components.
Encapsulation is the method of exposing all data and methods of an object to the outside world.
What is the purpose of the 'finally' block in exception handling?
To execute code regardless of whether an exception was thrown or not.
To catch specific exceptions only.
To define a new exception type.
To optimize the performance of the program.
Which of the following keywords is used to create an interface in Java?
extends
interface
implements
class
What is the output of the following code: System.out.println("Hello" + 5 + 10);?
Hello15
Hello510
15Hello
Hello 5 10
What is the purpose of the 'super' keyword in Java?
To define a new variable.
To implement an interface.
To create a new instance of a class.
To call a method from the parent class.
Which of the following is a valid way to create a string in Java?
String str = new String();
String str = new String("Hello");
String str = "Hello";
String str = String();
What does the 'this' keyword refer to in Java?
The static context of the class.
The method being executed.
The parent class instance.
The current object instance.
What is the purpose of the 'abstract' keyword in Java?
To create a new instance of a class.
To define a method that must be implemented by subclasses.
To declare a variable that cannot be changed.
To inherit properties from a parent class.
What is the result of the expression "Hello" + 3 + 4 in Java?
Hello 3 4
Hello34
Hello7
7Hello
Which of the following statements is true about interfaces in Java?
Interfaces can only contain abstract methods.
Interfaces cannot be implemented by classes.
Interfaces can extend multiple classes.
Interfaces can contain method implementations.
What is the purpose of the 'static' keyword in Java?
To define a method that can be called without creating an instance of the class.
To inherit properties from a parent class.
To create a new instance of a class.
To declare a variable that cannot be changed.
What is method overloading in Java?
Creating a method that overrides a parent class method.
Defining a method that cannot be overridden.
Defining multiple methods with the same name but different parameters.
Creating a method that is private to the class.
What is the output of the following code: System.out.println(10 % 3);?
10
0
1
3
What is the purpose of the 'volatile' keyword in Java?
To declare a variable that cannot be changed.
To define a method that must be implemented by subclasses.
To ensure that a variable is always read from main memory.
To create a new instance of a class.
What will be the output of the following code: System.out.println(5 + "5");?
10
55
5 5
5
What is the purpose of the 'synchronized' keyword in Java?
To define a method that can be called without creating an instance of the class.
To restrict access to a method or block to a single thread.
To allow multiple threads to access a method simultaneously.
To declare a variable that cannot be changed.
Which of the following statements about abstract classes in Java is true?
Abstract classes can be instantiated directly.
Abstract classes can contain both abstract and concrete methods.
Abstract classes cannot have constructors.
Abstract classes cannot have any fields.
What is the output of the following code: System.out.println(10 % 3);?
3
1
0
10
Which of the following is a valid way to declare a method in Java?
public myMethod() {}
myMethod void() {}
void myMethod public() {}
public void myMethod() {}
What is the purpose of the 'final' keyword in Java?
To create a new instance of a class.
To declare a variable that can be changed.
To define a method that can be overridden.
To prevent a class from being subclassed.
Which of the following statements about constructors in Java is true?
A constructor can have a return type.
A constructor is called when an object is created.
A constructor must be defined in every class.
A constructor can be private only.
What is the significance of the 'super' keyword in Java?
It is used to declare an interface.
It is used to call the parent class constructor.
It is used to create a new instance of a class.
It is used to define a static method.
What is the output of the following code: System.out.println(7 - 2 + "3");?
5 3
73
5
53
What does the 'static' keyword indicate in Java?
It allows a method to be called without creating an instance of the class.
It restricts the visibility of a method to the class itself.
It indicates that a variable can be changed at runtime.
It is used to define a method that can be overridden.
What is the result of the expression "10" + 5 * 2 in Java?
105
10
15
20
What is the output of the following code: System.out.println("Java" + " is fun!");?
Javaisfun!
is fun!Java
Java isfun!
Java is fun!
Which of the following is a correct way to declare an array in Java?
int arr[5];
int arr = new int[];
int arr[] = int[5];
int[] arr = new int[5];
What does the 'volatile' keyword indicate in Java?
It indicates that a variable can be accessed by multiple threads.
It is used to define a method that cannot be overridden.
It restricts the visibility of a variable to the class itself.
It allows a variable to be changed at runtime.
Which of the following keywords is used to define a constant variable in Java?
static
const
final
constant
What is the output of the following code: System.out.println("Java".length());?
4
5
3
6
Which of the following is a valid way to create a new thread in Java?
Thread t = new Thread(new Runnable());
All of the above
Thread t = new Thread();
Thread t = new Thread(() -> {});
What is the output of the following code: System.out.println("Hello" + " World");?
Hello World
Error
HelloWorld
"Hello" + " World"
Which of the following is a valid way to implement an interface in Java?
class MyClass extends MyInterface {}
class MyClass uses MyInterface {}
class MyClass inherits MyInterface {}
class MyClass implements MyInterface {}
What is the purpose of the 'final' keyword in Java?
All of the above
To create a constant value.
To define a method that cannot be overridden.
To declare a variable that cannot be changed.
Which of the following is a valid way to create a new instance of a class in Java?
new ClassName obj = ClassName();
ClassName obj = ClassName();
ClassName obj = create ClassName();
ClassName obj = new ClassName();
Hall_Ticket_Number
(a)
Gender
(a)
College/Branch
(a)
