Java OOP Fundamentals and Syntax Quiz
Java OOP Fundamentals and Syntax Quiz
1. What is the intermediate, platform-independent code generated by the Java Compiler (javac)
called? A. Machine Code B. Source Code C. Java Byte Code
D. Executable Code
D. Bill Joy
o Answer: C. James Gosling, Mike Sheridan, and Patrick Naughton initiated the project.
3. The process of
wrapping code and data together into a single unit (a class) is known as:
D. Information Hiding
only one copy of the variable is shared among all objects of that class?
o Answer: C. A static member is a class member, not an instance member, and is shared.
6. Which statement about a Java
Constructor is TRUE?
A. It must return void. B. It must be declared as public. C. It can be called using the this
reference. D. It must have the same name as the class and no return type.
A. The name of the package. B. The same name as the first method in the file. C. The same name as
the
public class within the file.
o Answer: C. The file name must match the name of the public class it contains.
8. The execution of any standalone Java application begins with the code inside the method signature:
o Answer: C. The full, required signature is public static void main(String args[]).
9. Java is a case sensitive programming language. Which two variables are treated as distinct?
A. int total; and int Total; B. int total; and String total; C. int total; and int
ToTaL; D. All of the above.
o Answer: C. The String args[] array holds the command-line inputs as individual strings.
2. Java is categorized as a High-Level Programming Language (3GL). What is the execution
approach followed by Object-Oriented Programming (OOP) languages like Java?
A. It is accessible only within the class. B. It is accessible only within the package. C. It is accessible
within the package AND by subclasses in any package.
D. It is globally accessible.
o Answer: C. protected provides package access and extends accessibility to subclasses
everywhere.
4. What does the keyword
o Answer: B. The this keyword is used to reference the current object (e.g., to resolve
namespace collision).
5. What mechanism allows an object to be automatically initialized at the time of its creation?
C. Overloading is used for interfaces; Overriding is used for abstract classes. D. Overriding requires
the final keyword; Overloading requires the static keyword.
o Answer: B. Overloading allows multiple methods with the same name but different
signatures, while Overriding redefines an inherited method.
7. Which statement accurately describes the use of a member declared as
private?
A. It is hidden from other classes but accessible by all methods in the same package. B. It is
accessible only within the class where it is declared.
C. It can be accessed by subclasses using the super keyword. D. It can be accessed by using a public
method from a different class.
o Answer: B. private is the strictest access modifier, restricting visibility to the containing
class.
8. What command is used to
A. java Example B.
javac [Link]
A. Dynamic Scope Rule (resolved at runtime) B. Static Scope Rule (resolved at compile time)
C. Global Scope Rule (always accessible) D. Local Scope Rule (restricted to blocks)
o Answer: B. Java follows a Static Scope Rule, where the visibility of variables is determined
during compilation.
10. Which term describes the ability to define
multiple constructors within a single class, differentiated only by their parameter lists?
A. It must also implement an interface. B. It must implement all methods, even non-abstract ones. C.
It can only extend one abstract class (Single Inheritance).
o Answer: C. Abstract classes are subject to Java's single inheritance rule for classes.
22. A method in a superclass is marked with the final keyword. What does this prevent?
A. The method from being called by a subclass object. B. The method from being overridden in any
subclass.
C. The method's body from containing an exception handler. D. The containing class from being
instantiated.
o Answer: B. The final keyword ensures the method's implementation is immutable by any
class that inherits it.
23. Which statement accurately describes the members of a Java
interface?
A. Methods can be concrete; fields must be private. B. Fields are implicitly public and static;
methods are implicitly public and native. C. Fields are implicitly
public, static, and final (constants); methods are implicitly public and abstract.
o Answer: C. Interface fields are global constants, and methods are abstract protocols.
24. Which keyword is used in a class declaration to acquire the behavior specified by an
interface?
A. extends B. inherits C.
implements
D. uses
C. Declaring all inherited methods as static. D. Nested classes that extend parent functionality.
o Answer: C. The try block encloses the code where an exception might occur, and the catch
block handles it.
27. The code within a
A. The try block executes normally. B. The try block throws a RuntimeException. C. A catch
block successfully handles the exception. D. The JVM itself terminates (e.g., due to a system error or
crash).
o Answer: D. In all normal flows, including those with return or unhandled exceptions,
finally executes. Only system-level failures can stop it.
28. What class in the Java API serves as the root of the
Exception/Error hierarchy?
A. [Link] B.
[Link]
C. [Link] D. [Link]
D. Exception Propagation
o Answer: C. This allows for localized handling of errors within a broader error-checking
scope.
30. The primary purpose of the
A. Explicitly create and launch an exception object. B. Declare that the method may propagate a
checked exception to its caller.
C. Force the calling method to use a finally block. D. Define a user-defined exception class.
o Answer: B. The throws clause is part of the method contract, informing other parts of the
program about unhandled checked exceptions.
21. If you create a custom exception class, which class must it extend?
A. [Link] B. [Link] C.
[Link]
D. [Link]
o Answer: C. All exceptions must be a child of the Throwable class, usually achieved by
extending Exception or RuntimeException.
22. What is the most significant advantage of designing a program to run in a
multithreaded manner?
A. It guarantees that the program will be logically correct. B. It enforces platform independence. C.
It improves system throughput and performance by executing tasks concurrently.
Running to Blocked/Waiting?
A. Using the start() method or finishing the run() method. B. Using the yield() method or
increasing priority. C. Calling
o Answer: C. The thread voluntarily enters the waiting state by calling methods like sleep(),
wait(), or when waiting for resources (I/O).
24. Which method must be
A. start() B. init() C.
run()
D. execute()
o Answer: C. The thread's actual sequence of instructions is contained in the run() method.
25. Which method is used to
temporarily halt a thread's execution, without terminating it, so that it can be later resumed?
A. stop() B.
suspend()
C. destroy() D. terminate()
o Answer: B. The suspend() method temporarily halts execution, and resume() is used to
bring it back to a runnable state.
26. What is the purpose of calling the
A. To force the thread to immediately terminate its execution. B. To merge the execution logic of
two different threads. C. To make the current thread wait until the thread object on which
o Answer: C. The join() method enforces sequential execution points, making one thread
wait for another to complete.
27. The highest priority that can be assigned to a thread is represented by the constant:
D. Thread.MIN_PRIORITY (value 1)
o Answer: C. Thread priorities range from 1 (MIN) to 10 (MAX), with 5 as the default (NORM).
28. Which type of stream is primarily used for handling
D. Object Stream
o Answer: C. Character streams (using Reader and Writer) deal with 16-bit Unicode, while
Byte Streams deal with 8-bit bytes.
29. To ensure previous buffered output data is physically written to the destination file or stream
immediately, which method should be called on the
A. close() B.
flush()
C. write() D. clear()
o Answer: B. The flush() method clears the buffer and forces the writing of any buffered
data.
30. When using the DataInputStream class, a common task is converting a String read from the input
into an integer. Which method is required for this conversion?
A. [Link]() B. [Link]() C.
[Link]()
D. [Link]()
A. A Frame is a lightweight component, while a Panel is heavyweight. B. A Panel can contain other
components, while a Frame cannot. C. A Frame has a title bar and window controls; a Panel does not
and is usually embedded in a Frame.
o Answer: C. The Frame is a top-level window with a title, whereas the Panel is a sub-
container without a title.
42. In a Swing application, which class is the base for creating a main application window (similar to
AWT's Frame)? A. [Link] B.
[Link]
C. [Link] D. [Link]
o Answer: B. The JFrame class is the Swing equivalent of the AWT Frame and is the basis for
most top-level Swing applications.
43. Which
Layout Manager arranges components in designated regions: North, South, East, West, and
Center?
A. FlowLayout B. BorderLayout
C. GridLayout D. CardLayout
o Answer: C. The GridLayout manager divides the container into a uniform number of rows
and columns.
45. Which of the following is typically designated as a
A. MouseListener B. ActionEvent C.
JButton
D. actionPerformed()
o Answer: C. The source is the component (e.g., button, list, text field) that generates the event
when interacted with by the user.
46. What is the name of the interface that defines methods like
A. MouseMotionListener B. AWTEventListener C.
MouseListener
D. ComponentListener
C. The <codebase> tag, which specifies the resource location. D. The <archive> tag, which bundles
necessary files.
o Answer: B. The <param> tag is explicitly used to pass configuration data as string values to
the applet.
48. What is the correct method used within an Applet's code to retrieve configuration data supplied via
the HTML <param> tags? A. getAppletInfo() B.
getParameter(String name)
C. getCodeBase() D. getDocumentBase()
o Answer: B. The getParameter() method is called by the applet to read the string value
associated with a parameter name.
49. Which of the following is an example of an
A. actionPerformed() B. itemStateChanged() C.
keyTyped()
D. windowClosing()
destroy() permanently removes the applet from memory (on quitting the browser).
C. destroy() halts execution temporarily; stop() permanently terminates the applet. D. stop() is
for the main thread; destroy() is for worker threads.
o Answer: B. stop() is a temporary pause, while destroy() is the final cleanup before
termination.
51. When developing a basic client-server application using TCP/IP in Java, which two classes are
required to manage the connection endpoints?
o Answer: B. ServerSocket listens for connections on the server side, and Socket establishes
the connection on the client side.
52. The communication protocol that is
o Answer: B. UDP is a connectionless protocol, commonly used for fast, unconfirmed data
transfer.
53. Which Java class is specifically used to retrieve information about a resource's location, including its
protocol, host, and file path?
A. InetAddress B. DatagramPacket C.
URL
D. StreamSocket
o Answer: C. The URL (Uniform Resource Locator) class encapsulates all the components of a
web address.
54. The process of dividing a large file or message into smaller pieces for transmission over a
connectionless network is called:
A. Streaming B. Buffering C. Synchronization D. Fragmentation (or Datagram creation)
o Answer: D. This is necessary for protocols like UDP, where the data unit is a datagram.
55. The JDBC process involves communicating a SQL command to a remote database server. Which
package contains all the necessary classes like
A. [Link] B. [Link] C.
[Link]
D. [Link]
o Answer: C. The [Link] package is the JDBC API for database connectivity.
56. Which method is used on a JDBC
Statement object to execute a query (like a SELECT statement) that returns a table of results?
A. executeUpdate(String sql) B.
executeQuery(String sql)
o Answer: B. executeQuery() is specifically for queries that return a result set, unlike
executeUpdate(), which is for DML (INSERT, UPDATE, DELETE).
57. After executing a
SELECT query via JDBC, what type of object is returned to the Java application to hold the retrieved
data (the table rows)?
A. Connection B. Statement C.
ResultSet
D. TableObject
o Answer: C. The ResultSet object acts as an iterator over the set of rows retrieved by the
query.
58. Which SQL command is used to add new rows (records) of data into an existing table?
INSERT INTO
o Answer: D. The INSERT INTO command populates a table with new data records.
59. In the JDBC process, what method is used on the
ResultSet object to move the cursor to the next available row of data?
A. nextRow() B.
next()
C. getRow() D. moveCursor()
o Answer: B. The next() method advances the cursor to the next row and returns true if a
new row is available.
60. Which SQL command is used to permanently remove an entire table (including its definition and all
data) from the database?
DROP TABLE
o Answer: D. The DROP TABLE command deletes the table structure and its contents
permanently.
Java Swing components superior to AWT components for complex visual applications?
A. Swing supports recursion, while AWT does not. B. Swing is purely interpreted, while AWT is
compiled. C. Swing provides a larger number of components (e.g.,
o Answer: C. Swing expands the toolkit with many sophisticated components essential for
complex GUIs.
62. When designing a complex GUI, what is the best practice for organizing numerous components
within a JFrame? A. Placing components directly into the JFrame using absolute coordinates. B.
Placing all components into a single JScrollPane. C. Grouping related components within separate
o Answer: B. CardLayout is ideal for simulating tabbed interfaces or wizards where views
must be swapped.
64. What happens if a Java Applet is hosted on an HTML page, but the corresponding
A. The browser closes due to a security violation. B. The browser may display the alternate text
provided in the
<applet> tag's alt attribute, or an error.
C. The Java Compiler is automatically invoked to recompile the source code. D. The Applet
successfully loads, but no display occurs.
o Answer: B. The optional alt tag provides a user-friendly message when the class file fails to
load.
65. Which method is typically called to
stop the execution thread of a banner applet when the user navigates away from the hosting web
page?
A. destroy() B. pause() C.
stop()
D. yield()
o Answer: C. The stop() method is used for temporary cessation of execution when the applet
is not visible.
66. What is the fundamental difference between
C. Byte Streams are for network I/O; Character Streams are for file I/O. D. Byte Streams support
buffering; Character Streams do not.
o Answer: B. The difference lies in the size of the data unit they handle: 8-bit for bytes vs. 16-
bit for characters.
67. Which of the following is considered a primary
A. They cannot establish network connections. B. They cannot use the [Link] package. C. They
are heavily restricted from reading or writing data to the local host's file system for security reasons.
o Answer: C. Applets run in a security sandbox and have strict limitations on local file access
and network communication to hosts other than their source.
68. When defining a user-defined exception class, which keyword in the constructor of the custom
exception is used to pass the error message up to the parent Exception class? A. this B. super C.
finally D. throw
o Answer: B. The super keyword is used in a subclass constructor to call a constructor of its
immediate superclass (the Exception class).
69. In multithreaded programming, a
A. A thread that must be executed with the highest priority. B. A low-priority thread that performs
general background services (e.g., Garbage Collector) and does not prevent the JVM from exiting.
C. A thread that exclusively runs the native C++ code. D. A thread that handles all I/O stream
operations.
o Answer: B. Daemon threads provide background support and are terminated immediately
when all non-daemon threads finish, allowing the JVM to exit.
70. What is the correct Java implementation practice when writing a method that needs to process all
rows in a JDBC
while ([Link]())
o Answer: B. The while ([Link]()) loop structure is the standard way to iterate through a
ResultSet row by row.
71. When using the [Link] package, which two classes are involved in setting up the client-side
endpoint for communication? A. ServerSocket and URL B. ServerAddress and PortNumber C.
InetAddress and Socket D. DatagramSocket and ServerSocket
o Answer: C. InetAddress helps resolve the server's address, and the Socket class creates the
client connection endpoint.
72. The process of connecting a Java application (Object-Oriented) to a relational database (RDBMS)
via JDBC is an example of:
o Answer: B. JDBC acts as a bridge between the object-oriented paradigm of Java and the
relational paradigm of SQL.
73. Which of the following is NOT a mandatory attribute for the HTML
<applet> tag?
codebase
fails to define all of the interface's abstract methods, what must that class be declared as?
A. final B. public C.
abstract
D. DELETE FROM...
o Answer: C. The method [Link]("Roll") retrieves the value of the column named Roll
from the current row, which must have been selected previously.
76. When an exception is deliberately caused by a developer to indicate an error state in a program,
which keyword is used?
A. throws B.
throw
C. finally D. catch
o Answer: B. The throw keyword explicitly dispatches an exception object (e.g., throw new
MyException()).
77. In AWT/Swing event handling, what method is used on a component (like a JTextField) to ensure
its associated TextListener is activated? A. registerTextListener(this) B.
handleTextEvent(this) C.
addTextListener(this)
D. setTextHandler(this)
A. Permanently terminate the thread after the specified time. B. Force another thread to start
execution immediately. C. Cause the currently executing thread to temporarily cease execution and
wait for the specified time (in milliseconds).
o Answer: C. sleep() voluntarily puts the thread into a waiting state for a defined duration.
79. What is the significance of using the
synchronized keyword on both the deposit() and withdraw() methods of a bank Account class?
D. It allows a single thread to execute both methods without using a thread scheduler.
o Answer: C. Synchronization is the tool used to protect critical sections and prevent data
corruption in concurrent access scenarios.
80. Java's I/O stream classes are primarily located in which two packages? A. [Link] and [Link]
B. [Link] and [Link] C.
o Answer: C. The legacy I/O classes are in [Link], and the newer, non-blocking I/O classes
are in [Link].
A. The physical Ethernet port on the computer. B. A software endpoint for communication, defined
by an IP Address and a Port Number.
C. The network interface card's MAC address. D. A dedicated thread for sending network data.
A. JDBC-ODBC Bridge Driver (Type 1) B. Native-API Driver (Type 2) C. Network Protocol Driver
(Type 3) D. Compiler Bridge Driver (Type 5)
D. private
o Answer: C. The Default access level is implied and restricts access to the current package.
85. Why are all member variables in a Java interface implicitly declared as
final?
A. To allow them to be accessed by non-static methods. B. To ensure they can be modified only once
during object creation. C. To ensure they act as constants whose values cannot be changed after
initialization.
o Answer: C. The final keyword makes the member a constant, enforcing that interfaces
provide only immutable definitions/constants.
86. Which SQL statement is executed to define the specific fields and data types of a new table in the
database?
A. INSERT INTO B.
CREATE TABLE
o Answer: B. The CREATE TABLE statement is used for Data Definition Language (DDL) tasks
to set up the table schema.
87. Which component is considered
heavyweight in the AWT/Swing hierarchy, meaning it relies on the host operating system's native
windowing toolkit?
A. JComponent B. JPanel C.
[Link]
D. [Link]
o Answer: C. All AWT components (like [Link]) are heavyweight and platform-
dependent, while Swing components are lightweight.
88. If a class is declared as
A. It prevents any of its methods from being overridden. B. It prevents the class from being
instantiated (no objects can be created).
C. It prevents the class from containing any non-abstract methods. D. It prevents the class from
inheriting from any superclass.
o Answer: B. An abstract class acts as a template or base for inheritance, and therefore cannot
be used to create concrete objects.
89. When reading a single line of text from a standard input device (keyboard) using the old
String
o Answer: D. Java I/O methods like readLine() return data in the form of a String, which
must then be converted to numerical types if needed.
90. What feature allows a single name (like a method name) to execute different operations based on
context or arguments (compile-time polymorphism)?
D. Overriding
o Answer: C. Polymorphism via Overloading (compile-time) uses the same name with
different signatures.
91. What is the meaning of the
public keyword in the main method signature (public static void main(...))?
A. It defines the entry point of the program. B. It ensures the method is accessible from outside the
class, allowing the JVM to start execution.
C. It prevents the method from returning any value. D. It specifies that the method is shared by all
objects.
A. The order in which the run() methods are defined. B. The explicit calling of join() on both
threads. C. The Thread Scheduler, based on priority and the underlying OS/JVM policy.
o Answer: C. Thread execution order is controlled by the Thread Scheduler, which manages
concurrent access to the CPU.
93. The purpose of using the
A. Call the current class's overloaded constructor. B. Explicitly invoke the constructor of the
immediate superclass.
C. Implement the abstract methods of an interface. D. Access a static variable in the immediate
parent class.
o Answer: B. super() is used to call a parent class's constructor, ensuring proper initialization
of inherited fields.
94. What happens if an Applet program tries to take input directly from the standard keyboard (
[Link])?
A. The program compiles successfully and reads the input. B. The operation is typically prohibited
due to security restrictions.
o Answer: B. Applets cannot use standard I/O (keyboard, file system) directly due to the
security sandbox.
95. In JDBC, what is the role of the
ResultSet object's getString(String columnName) method?
A. It converts a database string to a numerical type. B. It executes a SELECT query that returns only
string data. C. It retrieves the value of the specified column from the current row as a Java String.
o Answer: C. The method reads the data from the column in the current ResultSet row and
returns it as a Java String.
96. Which method is commonly used to introduce a visible pause or delay in a scrolling banner Applet
animation?
A. yield() B. wait() C.
sleep()
D. stop()
o Answer: C. The sleep() method is used to pause the current thread's execution for a
specific duration, necessary for controlling animation speed.
97. Which of the following is NOT a feature or component offered by the
RandomAccessFile class, which method is used to move the file pointer to a specific, arbitrary byte
position within the file?
seek(long pos)
D. read(byte[] b)
o Answer: C. The seek() method is the explicit function for random pointer positioning.
100. If a class is declared as final, what is the consequence for any attempt to inherit from it?
A. Only non-final methods can be inherited. B. Only methods using the protected modifier can be
overridden. C. The class can be instantiated only once. D. The class cannot be extended (no
subclasses are allowed).