WorksheetsJava Programming Quiz
Total questions: 60
Worksheet time: 30mins
What is the core principle of Java programming?
Declarative Programming
Procedural Programming
Object Oriented Programming
Functional Programming
Who developed Java?
Dennis Ritchie
James Gosling
Guido van Rossum
Bjarne Stroustrup
What was Java initially called?
C#
C++
Oak
JavaScript
What is the most important feature of Java?
Memory Management
Multi-threading
Platform-Independent
Platform-Dependent
What does OOP stand for?
Object Oriented Process
Object Oriented Protocol
Object Operated Programming
Object Oriented Programming
Which of the following is NOT a principle of OOP?
Inheritance
Encapsulation
Compilation
Polymorphism
What is encapsulation in Java?
Overriding methods
Creating interfaces
Inheriting properties
Hiding data and methods
What is a class in Java?
A blueprint for objects
A type of variable
A method of execution
A data structure
What is an object in Java?
A blueprint
A method
An instance of a class
A variable
Which of the following is a feature of Java?
Manual Memory Management
Automatic Garbage Collection
Complex Syntax
Static Typing
What is the purpose of the 'new' operator in Java?
To define a method
To declare a variable
To create an object
To create a class
What does JVM stand for?
Java Version Manager
Java Variable Manager
Java Virtual Machine
Java Visual Machine
What is the size of the 'int' data type in Java?
32 bits
16 bits
8 bits
64 bits
Which of the following is a primitive data type in Java?
Array
String
Boolean
Class
What is the range of the 'char' data type in Java?
0 to 65535
0 to 32767
0 to 1023
0 to 255
What is the default value of a boolean variable in Java?
true
false
0
1
Which of the following is used to handle exceptions in Java?
for loop
try-catch block
if-else statement
switch statement
What is the purpose of the 'break' statement in Java?
To declare a variable
To define a method
To continue to the next iteration
To exit a loop
What is the output of the following code: System.out.println(5 + 5);?
Error
50
55
10
Which of the following is a valid identifier in Java?
1stVariable
first variable
first-variable
firstVariable
What is the purpose of the 'return' statement in a method?
To exit the method
To return a value
To declare a variable
To create a loop
What is the correct way to declare an array in Java?
int arr[];
int[] arr;
None of the above
Both A and B
What is a multi-dimensional array in Java?
An array with no elements
An array of arrays
An array with multiple data types
A single array
What is the output of the following code: System.out.println(10 / 3);?
3
3.0
Error
3.33
Which of the following keywords is used to create a class in Java?
define
object
create
class
What is the purpose of the 'this' keyword in Java?
To define a method
To refer to the current object
To declare a variable
To create a new object
What is the output of the following code: System.out.println('A' + 1);?
66
A1
Error
65
Which of the following is NOT a valid loop in Java?
for loop
while loop
repeat-until loop
do-while loop
What is the purpose of the 'continue' statement in a loop?
To exit the loop
To skip the current iteration
To start a new loop
To declare a variable
What is the correct syntax for a switch statement?
switch(expression) { case: }
switch(expression) { case: break; }
switch { case: }
switch(expression) case:
What is the output of the following code: System.out.println(5 == 5);?
Error
false
true
5
Which of the following is a valid way to create a string in Java?
String str = "Hello';
String str = "Hello";
String str = 'Hello';
String str = Hello;
What is the purpose of the 'static' keyword in Java?
To create a class variable
To create a static variable
All of the above
To create a method that belongs to the class
What is the output of the following code: System.out.println(10 % 3);?
Error
3
1
0
Which of the following is a valid way to declare a method in Java?
methodName() void {}
void methodName() {}
void methodName()
methodName() {}
What is the purpose of the 'final' keyword in Java?
To declare a method
To declare a class
To declare a variable
To declare a constant
What is the output of the following code: System.out.println(5 + 5 + '5');?
55
10
Error
15
Which of the following is NOT a feature of Java?
Robust
Low-level programming
Object Oriented
Platform Independence
What is the purpose of the 'abstract' keyword in Java?
To declare a variable
To declare a method without a body
To declare a class that cannot be instantiated
Both A and B
What is the output of the following code: System.out.println(3 + 4 + 5);?
12
Error
7
34
Which of the following is a valid way to create an object in Java?
ClassName obj = ClassName;
ClassName obj = new ClassName();
ClassName obj = ClassName();
ClassName obj = new ClassName;
What is the output of the following code: System.out.println(10 - 3);?
Error
3
10
7
Which of the following is a valid way to handle exceptions in Java?
try-catch block
for loop
if-else statement
switch statement
What is the output of the following code: System.out.println(5 * 5);?
25
Error
10
55
Which of the following is a valid way to declare a boolean variable?
boolean flag = True;
boolean flag = true;
boolean flag = 1;
boolean flag = 'true';
What is the output of the following code: System.out.println(5 > 3);?
false
Error
true
5
Which of the following is a valid way to declare a character variable?
char c = 'A';
char c = A;
char c = "A";
char c = 'A';
What is the output of the following code: System.out.println(5 == 5);?
true
false
5
Error
Which of the following is a valid way to declare a float variable?
float f = 5;
float f = '5.0';
float f = 5.0f;
float f = 5.0;
What is the output of the following code: System.out.println(5 + 5 + 5);?
Error
5
10
15
Which of the following is a valid way to declare a double variable?
double d = 5.0;
double d = 5;
double d = 5.0d;
double d = '5.0';
What is the output of the following code: System.out.println(5 / 2);?
2
2.5
Error
5
Which of the following is a valid way to declare a long variable?
long l = '5';
long l = 5.0;
long l = 5L;
long l = 5;
What is the output of the following code: System.out.println(5 - 3);?
3
Error
2
5
Which of the following is a valid way to declare a short variable?
short s = 5.0;
short s = 5;
short s = 5S;
short s = '5';
What is the output of the following code: System.out.println(5 * 2);?
2
5
Error
10
Which of the following is a valid way to declare a byte variable?
byte b = 5.0;
byte b = '5';
byte b = 5B;
byte b = 5;
What is the output of the following code: System.out.println(5 % 2);?
5
Error
2
1
Which of the following is a valid way to declare a variable in Java?
int a = 5.0;
int a = 5;
int a = '5';
int a = 5L;
What is the output of the following code: System.out.println(5 + 5);?
Error
5
55
10
