NEW
Font size
S
M
L
XL
WorksheetsPreTest - JAVA
Total questions: 65
Worksheet time: 23mins
Name
Class
Date
1.
What is the size of int in Java?
a)
2 bytes
b)
4 bytes
c)
8 bytes
d)
Depends on OS
2.
Which of the following is not a Java keyword?
a)
static
b)
Integer
c)
void
d)
new
3.
What will 10 / 3 return in Java?
a)
3.333
b)
3
c)
0
d)
3.0
4.
Which access modifier makes a member visible to all classes?
a)
protected
b)
private
c)
default
d)
public
5.
Which of these is not a primitive type?
a)
int
b)
float
c)
String
d)
boolean
6.
What is the default value of a boolean variable?
a)
true
b)
false
c)
0
d)
null
7.
Which loop is guaranteed to execute at least once?
a)
for
b)
while
c)
do-while
d)
foreach
8.
What is the use of 'this' keyword?
a)
Refers to the superclass
b)
Refers to current class object
c)
Declares a class
d)
None of these
9.
What is returned by System.out.println("5" + 3);?
a)
8
b)
53
c)
Error
d)
None
10.
Java uses __ for memory management.
a)
Pointers
b)
Manual deletion
c)
Garbage Collection
d)
Destructors
11.
Which of the following are valid array declarations?
a)
int arr[];
b)
int[] arr;
c)
Both A and B
d)
None
12.
Which class is the superclass of all classes in Java?
a)
Object
b)
String
c)
System
d)
Class
13.
Which exception is thrown when array is accessed out of bounds?
a)
NullPointerException
b)
ArrayIndexOutOfBoundsException
c)
NumberFormatException
d)
ClassCastException
14.
Which method converts string to int?
a)
Integer.toString()
b)
Integer.parseInt()
c)
String.valueOf()
d)
parseInteger()
15.
Java source code is compiled into __
a)
Machine Code
b)
Bytecode
c)
Assembly
d)
Script
16.
What will be the output of: System.out.println(2 + 2 + '2');
a)
222
b)
42
c)
54
d)
24
17.
What will happen if a finally block is present?
a)
It will execute always
b)
It executes only when exception occurs
c)
It executes only if catch fails
d)
It never executes
18.
Which concept allows a subclass to provide specific implementation of a method?
a)
Inheritance
b)
Encapsulation
c)
Method Overriding
d)
Method Hiding
19.
Abstract class can have:
a)
Only abstract methods
b)
Only concrete methods
c)
Both abstract and concrete methods
d)
No methods
20.
Which keyword is used to prevent inheritance?
a)
static
b)
this
c)
final
d)
protected
21.
Which of the following is not part of Java Exception hierarchy?
a)
Throwable
b)
Error
c)
Exception
d)
Crash
22.
Which collection class maintains insertion order?
a)
HashMap
b)
TreeSet
c)
LinkedHashMap
d)
HashSet
23.
Which thread method causes current thread to wait for another to complete?
a)
sleep()
b)
wait()
c)
join()
d)
notify()
24.
Which functional interface is used in lambda expressions?
a)
Comparable
b)
Iterable
c)
Comparator
d)
All of these
25.
What is the default priority of a thread?
a)
1
b)
5
c)
10
d)
0
26.
What is the result of "abc".compareTo("abe")?
a)
1
b)
-2
c)
-1
d)
2
27.
Which class cannot be instantiated?
a)
String
b)
Object
c)
Abstract Class
d)
Arrays
28.
Which of the following is a marker interface?
a)
Runnable
b)
Serializable
c)
Comparable
d)
Cloneable
29.
Which stream is used to read text line by line?
a)
FileOutputStream
b)
FileInputStream
c)
BufferedReader
d)
DataInputStream
30.
Which keyword is used to handle exceptions?
a)
throw
b)
catch
c)
try
d)
Both B and C
31.
What is method overloading?
a)
Redefining a method in subclass
b)
Same name, different parameters
c)
Same name, same parameters
d)
Using static method
32.
What is the output of: true && false || true?
a)
true
b)
false
c)
error
d)
null
33.
Which class is used for creating immutable strings?
a)
String
b)
StringBuilder
c)
StringBuffer
d)
None
34.
What does transient keyword do?
a)
Makes variable final
b)
Excludes variable from serialization
c)
Synchronizes variable
d)
None
35.
Which of these is thread-safe?
a)
StringBuffer
b)
StringBuilder
c)
ArrayList
d)
HashMap
36.
What is the use of super keyword?
a)
Access parent constructor or methods
b)
Define superclass
c)
Access current class
d)
Access child constructor or methods
37.
What does the static keyword mean in Java?
a)
The method belongs to an object
b)
The method is abstract
c)
The method belongs to the class
d)
The method is thread-safe
38.
What is the default value of an object reference variable in Java?
a)
0
b)
null
c)
" "
d)
undefined
39.
Which exception is unchecked in Java?
a)
IOException
b)
SQLException
c)
NullPointerException
d)
ClassNotFoundException
40.
What happens if you call return inside a try block?
a)
finally won't execute
b)
Program exits
c)
finally will still execute
d)
Compilation error
41.
Which data structure uses FIFO order?
a)
Tree
b)
Graph
c)
Queue
d)
Stack
42.
Which data structure is best for implementing recursion?
a)
Queue
b)
Stack
c)
Array
d)
Tree
43.
Which traversal method is used for binary search trees to get sorted order?
a)
Pre-order
b)
In-order
c)
Post-order
d)
Level-order
44.
Which data structure is used for BFS in a graph?
a)
Stack
b)
Queue
c)
Tree
d)
Heap
45.
Which of these is not a linear data structure?
a)
Array
b)
Stack
c)
Binary Tree
d)
Queue
46.
What is the worst-case time complexity of quicksort?
a)
O(n^2)
b)
O(n log n)
c)
O(log n)
d)
O(n)
47.
Which sorting algorithm is best for nearly sorted data?
a)
Bubble Sort
b)
Insertion Sort
c)
Selection Sort
d)
Merge Sort
48.
Which data structure is used to implement a priority queue?
a)
Stack
b)
Queue
c)
Heap
d)
Array
49.
Which data structure supports insertion and deletion at both ends?
a)
Queue
b)
Stack
c)
Deque
d)
Heap
50.
What is the in-order traversal of a binary search tree?
a)
Left-Root-Right
b)
Root-Left-Right
c)
Right-Root-Left
d)
Root-Right-Left
51.
Which tree structure is used in database indexing?
a)
Binary Tree
b)
AVL Tree
c)
B-Tree
d)
Heap
52.
What is the degree of a leaf node?
a)
0
b)
1
c)
2
d)
-1
53.
What is the main disadvantage of linked list?
a)
Fixed size
b)
Random access not possible
c)
Inefficient insertion
d)
Slow sorting
54.
Which algorithm is used for cycle detection in graphs?
a)
Dijkstra
b)
DFS
c)
Kruskal
d)
Floyd
55.
Which data structure allows duplicate elements?
a)
Set
b)
Map
c)
Queue
d)
TreeSet
56.
Which keyword is used to sort the result-set?
a)
ORDER BY
b)
SORT
c)
ARRANGE BY
d)
GROUP BY
57.
Which command is used to remove all records from a table but keep the structure?
a)
REMOVE
b)
DROP
c)
DELETE
d)
TRUNCATE
58.
Which SQL clause groups rows sharing a property?
a)
GROUP BY
b)
ORDER BY
c)
WHERE
d)
SORT
59.
Which of the following is a valid SQL query?
a)
GET * FROM users;
b)
SELECT * WHERE name = 'John'
c)
SELECT name FROM users;
d)
CHOOSE name IN users;
60.
How to select unique values
a)
SELECT UNIQUE
b)
SELECT DISTINCT
c)
SELECT ONLY
d)
SELECT SINGLE
61.
OUTPUT?
a)
3
b)
0
c)
4
d)
3.0
62.
a)
7 7
b)
7 2
c)
7 5
d)
5 2
63.
OUTPUT?
a)
10
b)
5
c)
2
d)
20
64.
OUTPUT?
a)
12
b)
14
c)
8
d)
10
65.
OUTPUT?
a)
false true
b)
true true
c)
false false
d)
true false
Reset
