WorksheetsJava-Q3 Summative Test
Total questions: 125
Worksheet time: 1hrs 3mins
Name
Class
Date
1.
What is Object-Oriented Programming primarily based on?
a)
Functions
b)
Objects
c)
Algorithms
d)
Variables
2.
Which term represents a blueprint of an object?
a)
Method
b)
Attribute
c)
Class
d)
Package
3.
Which keyword is used to create an object in Java?
a)
class
b)
void
c)
new
d)
this
4.
An object is an instance of a—
a)
Method
b)
Variable
c)
Class
d)
Interface
5.
Which contains both data and methods?
a)
Loop
b)
Object
c)
Operator
d)
Package
6.
Which file extension is used for Java source code?
a)
.jav
b)
.java
c)
.class
d)
.exe
7.
Which access modifier allows visibility within the same class only?
a)
public
b)
protected
c)
default
d)
private
8.
Which term describes the behavior of an object?
a)
Attribute
b)
Method
c)
Class
d)
Package
9.
A student record system groups name, ID, and displayDetails(). What OOP concept is applied?
a)
Inheritance
b)
Encapsulation
c)
Polymorphism
d)
Abstraction
10.
Given Student s = new Student();, what does Student represent?
a)
Object
b)
Method
c)
Class
d)
Package
11.
Which scenario best represents an object?
a)
Blueprint of a car
b)
Car engine design
c)
A specific car with plate number
d)
Driving rules
12.
Why is OOP preferred for large systems?
a)
Faster execution
b)
Easier maintenance
c)
Shorter code
d)
Fewer files
13.
A Java program groups related classes under folders. What concept is applied?
a)
Package
b)
Method
c)
Loop
d)
Object
14.
Which design improves program organization?
a)
Using global variables
b)
Grouping logic into classes
c)
Writing code in main() only
d)
Avoiding methods
15.
A class without objects is best described as—
a)
Abstract design
b)
Unused code
c)
Error-prone
d)
Invalid
16.
Which statement correctly creates an object?
a)
Student();
b)
new Student;
c)
Student s = new Student();
d)
create Student s;
17.
What happens when multiple objects are created from one class?
a)
Program error
b)
Shared behavior, separate data
c)
Shared data only
d)
Same memory location
18.
A banking app models Account, Balance, and withdraw(). Which OOP idea is this?
a)
Modular design
b)
Object modeling
c)
Algorithm design
d)
Procedural logic
19.
Why should data and behavior be in one unit?
a)
Faster runtime
b)
Better security
c)
Reduced memory
d)
Easier debugging
20.
Which real-life analogy fits OOP best?
a)
Recipe list
b)
Toolbox with tools
c)
Blueprint and house
d)
Step-by-step manual
21.
A Java program uses multiple classes for different tasks. What benefit does this provide?
a)
Code duplication
b)
Code reuse
c)
More errors
d)
Slower execution
22.
Which OOP feature helps represent real-world entities?
a)
Arrays
b)
Objects
c)
Loops
d)
Operators
23.
Which class component stores object data?
a)
Method
b)
Constructor
c)
Attribute
d)
Package
24.
What is the role of a constructor?
a)
Destroy objects
b)
Initialize objects
c)
Call methods
d)
Display output
25.
Which practice reflects proper OOP design?
a)
All code in main
b)
Separate responsibilities into classes
c)
No methods
d)
Avoid objects
26.
Which OOP principle hides data?
a)
Inheritance
b)
Polymorphism
c)
Encapsulation
d)
Abstraction
27.
Which principle allows a class to inherit another class?
a)
Encapsulation
b)
Inheritance
c)
Polymorphism
d)
Abstraction
28.
Which principle allows many forms of a method?
a)
Inheritance
b)
Polymorphism
c)
Abstraction
d)
Encapsulation
29.
Which principle focuses on showing only essential details?
a)
Polymorphism
b)
Abstraction
c)
Inheritance
d)
Encapsulation
30.
Which keyword supports inheritance?
a)
this
b)
super
c)
extends
d)
implements
31.
Which access modifier best supports encapsulation?
a)
public
b)
protected
c)
default
d)
private
32.
Which method allows runtime method selection?
a)
Overloading
b)
Overriding
c)
Constructor
d)
Accessor
33.
Which feature improves code reuse?
a)
Polymorphism
b)
Abstraction
c)
Inheritance
d)
Encapsulation
34.
A class restricts direct access to its variables using private fields. What principle is applied?
a)
Inheritance
b)
Encapsulation
c)
Polymorphism
d)
Abstraction
35.
A subclass modifies a method from its parent class. What is this called?
a)
Overloading
b)
Overriding
c)
Hiding
d)
Encapsulation
36.
A method behaves differently based on the object calling it. Which principle applies?
a)
Inheritance
b)
Encapsulation
c)
Polymorphism
d)
Abstraction
37.
A programmer uses abstract classes to force implementation. Why?
a)
Speed
b)
Code security
c)
Standardization
d)
Memory usage
38.
Why use getters and setters?
a)
Faster execution
b)
Data hiding
c)
Code duplication
d)
Method overloading
39.
Which situation best fits inheritance?
a)
Student has a name
b)
Dog is an Animal
c)
Calculator adds numbers
d)
File reads data
40.
When should abstraction be used?
a)
When hiding implementation details
b)
When storing data
c)
When looping
d)
When printing output
41.
Which improves flexibility in system design?
a)
Inheritance
b)
Polymorphism
c)
Encapsulation
d)
Hardcoding
42.
A banking system has SavingsAccount and CurrentAccount. Which principle applies?
a)
Encapsulation
b)
Inheritance
c)
Abstraction
d)
Polymorphism
43.
Why is method overriding useful?
a)
Reduces memory
b)
Customizes behavior
c)
Avoids objects
d)
Removes inheritance
44.
Which principle prevents unauthorized data modification?
a)
Polymorphism
b)
Abstraction
c)
Encapsulation
d)
Inheritance
45.
Which design increases scalability?
a)
Procedural code
b)
Object-oriented design
c)
Hardcoded logic
d)
Single-class system
46.
Why avoid public variables?
a)
Slower access
b)
Security risk
c)
Syntax error
d)
Compilation failure
47.
Which OOP principle allows treating subclasses as superclass objects?
a)
Inheritance
b)
Encapsulation
c)
Polymorphism
d)
Abstraction
48.
When should inheritance be avoided?
a)
Tight coupling exists
b)
Code reuse needed
c)
Relationship is “is-a”
d)
Shared behavior exists
49.
Which practice improves maintainability?
a)
Encapsulation
b)
Global variables
c)
Code repetition
d)
Large methods
50.
Which OOP principle supports framework development?
a)
Abstraction
b)
Polymorphism
c)
Encapsulation
d)
Inheritance
51.
What is an exception in Java?
a)
A syntax error
b)
A runtime event that disrupts program flow
c)
A logical mistake
d)
A compiler directive
52.
Which block contains code that may cause an exception?
a)
catch
b)
finally
c)
try
d)
throws
53.
Which block executes whether an exception occurs or not?
a)
try
b)
catch
c)
finally
d)
throw
54.
Which keyword is used to handle an exception?
a)
throw
b)
throws
c)
catch
d)
finally
55.
Which exception occurs when dividing by zero?
a)
IOException
b)
ArithmeticException
c)
NumberFormatException
d)
NullPointerException
56.
Which keyword is used to manually generate an exception?
a)
try
b)
throw
c)
throws
d)
catch
57.
Which exception is checked at compile time?
a)
RuntimeException
b)
ArithmeticException
c)
IOException
d)
NullPointerException
58.
Which package contains most built-in Java exceptions?
a)
java.util
b)
java.io
c)
java.lang
d)
java.exception
59.
A program reads a file but crashes when the file is missing. What should be added?
a)
Loop
b)
try–catch block
c)
Conditional only
d)
Method overloading
60.
Given the code:
try {
int x = 10 / 0;
} catch (ArithmeticException e) {
System.out.print("Error");
}
What is the output?
a)
0
b)
10
c)
Error
d)
Program terminates
61.
A method may throw an IOException but does not handle it internally. What is required?
a)
finally block
b)
catch block
c)
throws IOException
d)
return statement
62.
Why should specific exceptions be caught instead of generic Exception?
a)
Faster execution
b)
Clearer error handling
c)
Shorter code
d)
Compiler requirement
63.
Which exception occurs when accessing an object that is null?
a)
IOException
b)
ArithmeticException
c)
NullPointerException
d)
ArrayIndexOutOfBoundsException
64.
You want to ensure a file is closed after reading, regardless of errors. Which block is best?
a)
try
b)
catch
c)
throws
d)
finally
65.
A program crashes due to invalid numeric input from the user. Which exception should be handled?
a)
IOException
b)
NumberFormatException
c)
ArithmeticException
d)
ClassNotFoundException
66.
Which practice improves program reliability?
a)
Ignoring exceptions
b)
Using try–catch blocks
c)
Using global variables
d)
Removing error checks
67.
Which scenario best requires exception handling?
a)
Printing output
b)
File input operation
c)
Loop iteration
d)
Variable assignment
68.
What happens if an exception is not handled?
a)
Program continues
b)
Program terminates
c)
Compiler fixes it
d)
Exception ignored
69.
A developer creates a custom exception class. Why?
a)
Improve performance
b)
Simplify syntax
c)
Provide meaningful error messages
d)
Avoid try–catch
70.
Which keyword passes an exception to the calling method?
a)
throw
b)
throws
c)
catch
d)
finally
71.
Which catch block should appear first?
a)
Parent exception
b)
Child exception
c)
RuntimeException
d)
IOException
72.
A program needs to display user-friendly messages when errors occur. What is the best solution?
a)
System.exit()
b)
try–catch with custom messages
c)
Ignore exception
d)
Use assertions
73.
Which exception commonly occurs when parsing strings to numbers?
a)
IOException
b)
ArithmeticException
c)
NumberFormatException
d)
NullPointerException
74.
Why use user-defined exceptions?
a)
Faster runtime
b)
Better program logic clarity
c)
Fewer classes
d)
Avoid inheritance
75.
Which practice reflects proper exception handling?
a)
Catching all exceptions as Exception
b)
Ignoring checked exceptions
c)
Catching specific exceptions
d)
Using exceptions for flow control
76.
Which interface represents an ordered collection?
a)
Set
b)
Map
c)
List
d)
Iterator
77.
Which collection does NOT allow duplicate elements?
a)
ArrayList
b)
LinkedList
c)
HashSet
d)
Vector
78.
Which interface stores key–value pairs?
a)
List
b)
Set
c)
Map
d)
Collection
79.
Which implementation automatically sorts elements?
a)
HashSet
b)
TreeSet
c)
ArrayList
d)
LinkedList
80.
Which Map allows one null key?
a)
Hashtable
b)
TreeMap
c)
HashMap
d)
Properties
81.
Which interface is used to traverse collections?
a)
Comparable
b)
Comparator
c)
Iterator
d)
Enumeration
82.
Which collection maintains insertion order?
a)
HashSet
b)
TreeSet
c)
ArrayList
d)
Hashtable
83.
Which loop is commonly used with collections?
a)
while
b)
do-while
c)
enhanced for
d)
switch
84.
You need fast searching and no duplicates. Which collection is best?
a)
ArrayList
b)
LinkedList
c)
HashSet
d)
TreeMap
85.
A program must store student ID and name pairs. Which structure fits best?
a)
List
b)
Set
c)
Map
d)
Queue
86.
Which collection should be used when sorted order is required?
a)
HashSet
b)
TreeSet
c)
ArrayList
d)
LinkedList
87.
A program frequently inserts and removes elements. Which List is best?
a)
ArrayList
b)
LinkedList
c)
Vector
d)
Stack
88.
Which Map implementation maintains sorted keys?
a)
HashMap
b)
Hashtable
c)
TreeMap
d)
LinkedHashMap
89.
What happens if you add a duplicate value to a Set?
a)
Error occurs
b)
Program crashes
c)
Duplicate ignored
d)
Value replaced
90.
A word-count program should use which collection?
a)
List
b)
Set
c)
Map
d)
Queue
91.
Which loop avoids index-related errors in collections?
a)
traditional for
b)
while
c)
enhanced for
d)
do-while
92.
Which collection guarantees unique keys?
a)
List
b)
Set
c)
Map
d)
Queue
93.
When is LinkedHashMap preferred?
a)
When sorting needed
b)
When insertion order matters
c)
When no nulls allowed
d)
When thread safety needed
94.
Which class allows bidirectional traversal?
a)
Iterator
b)
ListIterator
c)
Enumeration
d)
Comparator
95.
Which collection improves flexibility and scalability?
a)
Arrays
b)
Collections
c)
Primitive variables
d)
Constants
96.
Which interface removes duplicates automatically?
a)
List
b)
Set
c)
Map
d)
Iterator
97.
Which structure best models a dictionary?
a)
List
b)
Set
c)
Map
d)
Stack
98.
Which collection supports dynamic resizing?
a)
Array
b)
List
c)
Primitive variable
d)
Constant
99.
Why use collections instead of arrays?
a)
Faster compilation
b)
Fixed size
c)
Dynamic size and utilities
d)
Less memory usage
100.
Which practice reflects proper collection usage?
a)
Hardcoding sizes
b)
Using appropriate collection types
c)
Avoiding iterators
d)
Using arrays only
101.
Which package supports file handling?
a)
java.lang
b)
java.util
c)
java.io
d)
java.file
102.
Which class represents a file or directory path?
a)
FileReader
b)
FileWriter
c)
File
d)
Scanner
103.
Which method checks if a file exists?
a)
isFile()
b)
exists()
c)
check()
d)
available()
104.
Which method creates a new file?
a)
mkdir()
b)
createNewFile()
c)
open()
d)
write()
105.
Which method deletes a file?
a)
erase()
b)
delete()
c)
clear()
d)
remove()
106.
Which class reads byte-based data?
a)
FileReader
b)
FileInputStream
c)
BufferedReader
d)
Scanner
107.
Which class reads character-based data?
a)
FileInputStream
b)
FileReader
c)
ObjectInputStream
d)
DataInputStream
108.
Which method creates a directory?
a)
createNewFile()
b)
mkdir()
c)
exists()
d)
delete()
109.
A program must check if a file exists before reading. What should be used?
a)
Loop
b)
exists() method
c)
Hardcoded value
d)
Exception only
110.
Which exception commonly occurs during file operations?
a)
ArithmeticException
b)
IOException
c)
NullPointerException
d)
RuntimeException
111.
A program needs to write text data to a file. Which class is best?
a)
FileInputStream
b)
FileReader
c)
FileWriter
d)
Scanner
112.
A directory cannot be deleted. Why?
a)
Wrong method
b)
Not empty
c)
File name error
d)
Missing path
113.
Why should file streams be closed?
a)
Improve syntax
b)
Prevent resource leaks
c)
Reduce code length
d)
Speed compilation
114.
A program writes data but nothing appears in the file. What is likely missing?
a)
append mode
b)
close() method
c)
delete() method
d)
exists() check
115.
Which method renames a file?
a)
rename()
b)
renameTo()
c)
move()
d)
change()
116.
A program must overwrite file content. Which approach applies?
a)
Append mode
b)
Default FileWriter
c)
BufferedReader
d)
Scanner
117.
Which practice ensures safe file handling?
a)
Ignoring exceptions
b)
Using try–catch
c)
Using global paths
d)
Avoiding close()
118.
Which File method returns file size?
a)
size()
b)
length()
c)
count()
d)
getSize()
119.
Which operation creates nested directories?
a)
mkdir()
b)
mkdirs()
c)
createNewFile()
d)
exists()
120.
Which scenario requires java.io package?
a)
Sorting data
b)
File storage
c)
Looping arrays
d)
String concatenation
121.
Why should file existence be checked before deletion?
a)
Avoid syntax errors
b)
Prevent runtime errors
c)
Improve speed
d)
Reduce memory
122.
A program deletes processed files. What must be verified first?
a)
File size
b)
File exists
c)
File name
d)
File extension
123.
Which class represents file metadata, not content?
a)
File
b)
FileReader
c)
BufferedReader
d)
Scanner
124.
Which method checks if a path is a directory?
a)
isFile()
b)
isDirectory()
c)
exists()
d)
mkdir()
125.
Which practice reflects proper file I/O management?
a)
Hardcoded paths
b)
Closing streams properly
c)
Ignoring errors
d)
Using global variables
100 %
