NEW
Font size
WorksheetsJava Programming Quiz
Total questions: 25
Worksheet time: 13mins
What is the primary feature of Java that allows code to run on any device that supports the JVM?
Write Once, Run Anywhere
Compile Once, Run Anywhere
Write Once, Compile Anywhere
Run Anywhere, Write Once
Which of the following is NOT a core principle of Object-Oriented Programming (OOP) in Java?
Inheritance
Polymorphism
Encapsulation
Compilation
What is the output of the following Java code: System.out.println("Hello World");?
Hello World
Hello
World
Error
Which Java framework is commonly used for building enterprise applications?
Ruby on Rails
Flask
Django
Spring
What type of method allows you to pass a variable number of arguments in Java?
Varargs
Abstract Method
Instance Method
Static Method
Which of the following is a collection interface in Java?
Character
Integer
String
List
What keyword is used to handle exceptions in Java?
try
catch
All of the above
throw
Which of the following is used to create a thread in Java?
Thread Class
Both A and B
Executor Service
Runnable Interface
What is the purpose of the 'final' keyword in Java?
All of the above
To declare constants
To prevent method overriding
To prevent inheritance
Which of the following is a valid way to declare an array in Java?
int arr[] = new int[5];
int[] arr = new int[5];
int arr[] = new int(5);
int arr = new int[5];
What is the main purpose of Java's garbage collection?
To free up memory
To compile code
To handle exceptions
To manage threads
Which of the following is NOT a Java access modifier?
static
private
protected
public
What does JVM stand for?
Java Version Manager
Java Virtual Machine
Java Variable Method
Java Visual Machine
Which of the following is a feature of Java?
Multiple Inheritance
Low-level programming
Platform Independence
Pointer Arithmetic
What is the default value of a boolean variable in Java?
true
false
0
1
Which of the following is a valid way to create an instance of a class in Java?
ClassName obj = ClassName.new();
ClassName obj = new ClassName();
ClassName obj = new ClassName;
ClassName obj = ClassName();
What is the purpose of the 'synchronized' keyword in Java?
To allow multiple threads to access a method
To prevent thread interference
To create a new thread
To declare a method as final
What is the purpose of the 'this' keyword in Java?
To declare a static variable
To call a superclass method
To create a new instance
To refer to the current object
Which of the following is a valid way to implement an interface in Java?
class MyClass MyInterface {}
class MyClass extends MyInterface {}
class MyClass implements MyInterface {}
class MyClass implements MyInterface()
What is the main advantage of using interfaces in Java?
To restrict access to methods
To improve performance
To provide a blueprint for classes
To achieve multiple inheritance
What is the role of the 'static' keyword in Java?
To declare abstract classes
To restrict method access
To define class-level methods and variables
To create instance variables
Which of the following is a feature of Java's exception handling?
Runtime checking
Compile-time checking
Both A and B
None of the above
What is the purpose of the 'super' keyword in Java?
To declare a static method
To create a new instance of a class
To refer to the superclass of the current object
To call a constructor of the current class
What is the main purpose of the 'volatile' keyword in Java?
To ensure thread safety
To declare a constant variable
To create a synchronized block
To prevent method overriding
What is the purpose of the 'abstract' keyword in Java?
To define a method without implementation
To create a final class
To declare a static method
To implement multiple inheritance
