Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

NRG Pre-Test 2025

Total questions: 60

Worksheet time: 30mins

Name
Class
Date
1.
Which of the following is a primitive data type in Java?
a)
String
b)
Integer
c)
float
d)
Double
2.
What is the default value of an uninitialized boolean variable in Java?
a)
true
b)
false
c)
null
d)
undefined
3.
Which of the following is not a valid identifier in Java?
a)
_first_name
b)
First_Name
c)
first name
d)
firstName
4.
Which of the following is a valid way to declare a multi-dimensional array in Java? (Choose two)
a)
int[] arr = {1, 2, 3};
b)
int[][] arr = {{1, 2}, {3, 4}};
c)
int[2][2] arr = {{1, 2}, {3, 4}};
d)
int arr[][] = {{1, 2}, {3, 4}};
5.
What is the difference between a while loop and a do-while loop in Java?
a)
A while loop is always executed at least once, while a do-while loop may not be executed at all.
b)
A do-while loop is always executed at least once, while a while loop may not be executed at all.
c)
A while loop and a do-while loop are the same thing.
d)
A do-while loop is faster than a while loop.
6.
What is the difference between a break statement and a continue statement in Java?
a)
A break statement terminates the current loop, while a continue statement skips the current iteration of the loop.
b)
A continue statement terminates the current loop, while a break statement skips the current iteration of the loop.
c)
A break statement and a continue statement are the same thing.
d)
A continue statement is faster than a break statement.
7.
What is the purpose of the "final" keyword in Java?
a)
To indicate that a variable cannot be changed once it has been initialized.
b)
To indicate that a class cannot be extended or overridden.
c)
To indicate that a method cannot be overridden.
d)
All of the above.
8.
Which of the following is not a valid way to implement an interface in Java?
a)
class MyClass implements MyInterface {}
b)
class MyClass extends MyInterface {}
c)
class MyClass implements MyInterface { public void method() {} }
d)
All of the above are
9.
What is the output of the following code snippet? int i = 0; while (i < 10) { System.out.print(i); i += 2; }
a)
0 2 4 6 8
b)
0 1 2 3 4 5 6 7 8 9
c)
2 4 6 8 10
d)
1 3 5 7 9
10.
What is the output of the following code snippet? int x = 10; int y = 3; System.out.println(x / y);
a)
3
b)
3.0
c)
3.333
d)
3.3333...
11.
What is the difference between "==" and ".equals()" in Java?
a)
"==" compares the values of two objects, while ".equals()" compares the references of two objects.
b)
"==" compares the references of two objects, while ".equals()" compares the values of two objects.
c)
"==" and ".equals()" are the same thing in Java.
d)
None of the above.
12.
What is the default value of an integer in Java?
a)
0
b)
1
c)
null
d)
-1
13.
What is the difference between an array and a list in Java?
a)
An array is a fixed-size data structure, while a list can be resized.
b)
An array can store only primitive types, while a list can store objects.
c)
An array can store objects, while a list can store only primitive types.
d)
There is no difference between an array and a list in Java.
14.
What is the purpose of the 'this' keyword in Java?
a)
It refers to the current class instance.
b)
It refers to the parent class instance.
c)
It refers to the child class instance.
d)
It refers to the current method.
15.
What is the output of the following code snippet?
a)
Parent class Child class
b)
Child class Parent class
c)
Child class
d)
Parent class
16.
What is the purpose of the break keyword in Java?
a)
It terminates the current iteration of a loop.
b)
It terminates the entire loop.
c)
It transfers control to the next statement.
d)
It indicates that a variable or method is public.
17.
What is the purpose of the extends keyword in Java?
a)
It indicates that a class is a subclass of another class.
b)
It indicates that a class is a superclass of another class.
c)
It indicates that a class is an interface.
d)
It indicates that a class is a final class.
18.
What does OOP means?
a)
Object-Oriented Programming
b)
Oriented-Object Programming
c)
Option-Object Programming
d)
Option-Oriented Programming
19.
It is the mechanism that binds data and methods that manipulate data and protects them from outside interference or misuse.
a)
Encapsulation
b)
Inheritance
c)
Polymorphism
d)
Abstraction
20.
It is the mechanism that allows a class to inherit properties and methods from its parent class.
a)
Encapsulation
b)
Inheritance
c)
Polymorphism
d)
Abstraction
21.
It is the ability of an object to take many forms or have many behaviors.
a)
Encapsulation
b)
Inheritance
c)
Polymorphism
d)
Abstraction
22.
It is the process of hiding implementation details and showing only the necessary features of an object.
a)
Encapsulation
b)
Inheritance
c)
Polymorphism
d)
Abstraction
23.
What is the output of the following code snippet?
a)
num is a even number
b)
num is a odd number
c)
11 is a even number
d)
11 is a odd number
24.
What is the output of the following code snippet?
a)
3
b)
10
c)
1
d)
0
25.
What is the output of the following code snippet?
a)
Adult
b)
Minor
c)
adult
d)
minor
26.
What is the output of the following code snippet?
a)
true
b)
false
27.
What is the output of the following code snippet?
a)
false6
b)
false7
c)
true6
d)
true7
28.
What is the output of the following code snippet?
a)
1 is a positive number
b)
1.6 is a positive number
c)
num1 is a positive number
d)
num1 is neither positive or negative number
29.
What is the output of the following code snippet?
a)
x is greater than 5
b)
x is less than or equal to 5
c)
10 is greater than 5
d)
10 is less than or equal to 5
30.
What is the output of the following code snippet?
a)
7
b)
8
c)
6
d)
Error
31.
What is the output of the following code snippet?
a)
1 2 3 4 5
b)
1 3 5
c)
2 4 6
d)
1 1 1 1 1
32.
What is the output of the following code snippet?
a)
5 3 1
b)
2 4 6
c)
5 3
d)
5 4 3 2 1
33.
What is the output of the following code snippet?
a)
6
b)
7
c)
8
d)
9
34.
What is the output of the following code snippet?
a)
0 1 2 3 4
b)
1 2 3 4 5
c)
2 3 4 5
d)
1
35.
What is the output of the following code snippet?
a)
1 3
b)
1 3 5
c)
1 2 3
d)
1 2 3 4 5
36.
What is the index of the first element in an single dimensional array?
a)
0
b)
1
c)
-1
d)
null
37.
What is the output of the following code snippet?
a)
1
b)
2
c)
3
d)
4
38.
What is the output of the following code snippet?
a)
2
b)
4
c)
6
d)
8
39.
What is the output of the following code snippet?
a)
0
b)
2
c)
null
d)
error
40.
What is the output of the following code snippet?
a)
1 2 3
b)
3 2 1
c)
1 3 2
d)
ArrayIndexOutofBoundsException
41.
What does OOP stand for in Java?
a)
Object-Oriented Programming
b)
Object-Oriented Paradigm
c)
Object-Oriented Procedure
d)
Object-Oriented Protocol
42.
Which of the following is NOT a principle of Object-Oriented Programming?
a)
Inheritance
b)
Encapsulation
c)
Procedural Programming
d)
Polymorphism
43.
Which of the following is an example of runtime polymorphism in Java?
a)
Method Overloading
b)
Method Hiding
c)
Method Overriding
d)
Method Encapsulation
44.
What is the process of wrapping data and methods into a single unit called?
a)
Inheritance
b)
Encapsulation
c)
Abstraction
d)
Polymorphism
45.
Which of the following statements about abstract classes in Java is NOT true?
a)
A class can inherit from multiple abstract classes.
b)
An abstract class cannot be instantiated directly.
c)
Abstract methods can only be defined in abstract classes.
d)
An abstract class can have both abstract and non-abstract methods.
46.
Which of the following statements about interfaces in Java is true?
a)
An interface can extend multiple classes.
b)
An interface can be instantiated using the new keyword.
c)
An interface can have private methods.3
d)
A class can implement multiple interfaces.
47.
What is the process of creating multiple methods with the same name but different parameters within a class called?
a)
Inheritance
b)
Encapsulation
c)
Polymorphism
d)
Abstraction
48.
Which keyword is used to call the superclass constructor from the subclass in Java?
a)
super
b)
this
c)
new
d)
extends
49.
What is the term for creating an object from a class in Java?
a)
Inheritance
b)
Implementation
c)
Invocation
d)
Instantiation
50.
Which keyword is used to explicitly indicate that a method needs to be overridden by subclasses?
a)
override
b)
implements
c)
final
d)
abstract
51.
What is the output of the following code snippet?
a)
MyInterface
b)
Compilation Error
c)
MyClass
d)
Runtime Error
52.
What is the output of the following code snippet?
a)
10
b)
Compilation Error
c)
0
d)
Runtime Error
53.
What is the output of the following code snippet?
a)
5
b)
6
c)
Compilation Error
d)
Runtime Error
54.
What is the output of the following code snippet?
a)
10
b)
0
c)
Compilation Error
d)
Runtime Exception Error
55.
What is the output of the following code snippet?
a)
Constructor of class B Constructor of class A
b)
Constructor of class A Constructor of class B
c)
Compilation error
d)
Runtime exception
56.
What is the output of the following code snippet?
a)
MyClass MySubclass
b)
Compilation Error
c)
MySubclass MyClass
d)
Runtime Exception Error
57.
Which two modification, made independently, enable to code to compile? (Choose 2)
a)
Make the method at line 1 public
b)
Make the method at line 3 public
c)
Make the method at line 4 public
d)
Make the method at line 3 protected
e)
Make the method at line 2 public
58.
What is the output of the following code snippet?
a)
Display method
b)
Error at line 2
c)
Error at line 3
d)
Error at line 1
59.
What is the output of the following code snippet?
a)
Class B Class A
b)
Class A
c)
Class A Class B
d)
Class B
60.
What is the output of the following code snippet?
a)
Method A of class A Method B of class B
b)
Error at line 1
c)
Method B of class B Method B of class B
d)
Error at line 2