Java Quiz

Java Quiz

Test your knowledge of the Java programming language with this 12-question quiz!

published on January 13
1/12

Which of the following is not a primitive data type in Java?

Which of the following is not a primitive data type in Java?
int
boolean
string
double
2/12

What is the output of the following code snippet?

int x = 5;
System.out.println(x++);

4
5
6
Compilation error
3/12

What is the main purpose of using 'break' statement in Java?

What is the main purpose of using 'break' statement in Java?
To terminate the current loop
To continue to the next iteration of the loop
To throw an exception
To define a custom label for the loop
4/12

Which keyword is used to inherit a class in Java?

Which keyword is used to inherit a class in Java?
super
abstract
new
extends
5/12

Which data structure provides a last-in, first-out (LIFO) ordering?

ArrayList
LinkedList
HashMap
Stack
6/12

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

What is the default value of an instance variable in Java?
0
null
false
Depends on the data type
7/12

Which exception is thrown when an array index is out of bounds?

Which exception is thrown when an array index is out of bounds?
ArrayIndexOutOfBoundsException
NullPointerException
ArithmeticException
IndexOutOfBoundsException
8/12

What is the entry point method in a Java program?

What is the entry point method in a Java program?
start()
init()
main()
run()
9/12

Which access modifier makes a class or method accessible within the same package?

Which access modifier makes a class or method accessible within the same package?
protected
private
public
default
10/12

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

What is the purpose of the 'final' keyword in Java?
To define a class that cannot be inherited
To prevent a method from being overridden
To declare a constant variable
To specify a default value for a variable
11/12

What does the 'synchronized' keyword in Java ensure?

Thread safety
Code simplicity
Efficient memory usage
Exception handling
12/12

What is the purpose of the 'equals()' method in Java?

What is the purpose of the 'equals()' method in Java?
To compare two distinct objects
To compare two primitive data types
To compare the content of two objects
To check if an object is null