0% found this document useful (0 votes)
18 views20 pages

Java OOP Fundamentals and Syntax Quiz

The document consists of a series of questions and answers related to Java programming, covering topics such as object-oriented programming (OOP) principles, exception handling, multithreading, and GUI components. Each question tests knowledge on specific Java concepts, with correct answers provided for each. The content is structured in sections, addressing fundamental concepts, advanced OOP, and GUI/networking/database aspects of Java.

Uploaded by

naveen.cr.csm
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views20 pages

Java OOP Fundamentals and Syntax Quiz

The document consists of a series of questions and answers related to Java programming, covering topics such as object-oriented programming (OOP) principles, exception handling, multithreading, and GUI components. Each question tests knowledge on specific Java concepts, with correct answers provided for each. The content is structured in sections, addressing fundamental concepts, advanced OOP, and GUI/networking/database aspects of Java.

Uploaded by

naveen.cr.csm
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Section 1: Fundamentals, OOP, and Core Syntax (Questions 1-20)

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

o Answer: C. Java Byte Code is executed by the JVM.


2. Java was initiated by the

Green Team of Sun engineers in June 1991, led by whom?

A. Patrick Naughton B. Mike Sheridan C. James Gosling

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:

A. Inheritance B. Polymorphism C. Encapsulation

D. Information Hiding

o Answer: C. This defines the OOP paradigm of Encapsulation.


4. Which OOP paradigm is necessary to achieve

Dynamic Binding (method resolved at runtime)?

A. Encapsulation B. Abstraction C. Inheritance D. Polymorphism

o Answer: D. Dynamic Binding is a form of Runtime Polymorphism.


5. Which keyword, when applied to a class field, ensures that

only one copy of the variable is shared among all objects of that class?

A. final B. transient C. static D. public

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.

o Answer: D. The lack of a return type is mandatory for constructors.


7. A program compiled with javac produces a .class file. What must the name of the

Java source file (.java) be?

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.

D. A name matching the main method signature.

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:

A. public void main(String args[]) B. public static String main(String args[]) C.

public static void main(String args[])

D. private static void main(String args[])

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: D. Any difference in casing makes identifiers distinct in Java.


10. Which statement is generally TRUE about Java applications compared to C/C++ programs? A. Java
supports pointers, unlike C++. B. Java is purely compiled, unlike C++. C. Java does not support
multiple inheritance for classes, unlike C++.

D. Java uses an assembler to convert Byte Code to machine code.

o Answer: C. C++ supports multiple inheritance, while Java does not.

1. How are command-line arguments passed to a Java application?

A. As a single String object delimited by spaces. B. As an array of characters, which must be


manually parsed. C. As an array of String objects, stored in the

String args[] parameter.

D. As an array of generic Object types.

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. Top-Down Approach B. Bottom-Up Approach

C. Modular Approach D. Iterative Approach

o Answer: B. OOP focuses on objects first (Bottom-Up), whereas Function-Oriented


Programming (FOP) is Top-Down.
3. What is the significance of declaring a member (field or method) with the

protected access modifier?

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

this refer to in Java?

A. The immediate superclass object. B. The current object instance.

C. The class's static members. D. The currently running Thread.

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?

A. Factory Method B. Initialization Block C. Setter Methods D. Constructor

o Answer: D. The constructor is a special method used for automatic initialization.


6. What is the fundamental difference between Method Overloading and Method Overriding? A.
Overriding happens at compile time; Overloading happens at runtime. B. Overloading changes the
method signature (parameters); Overriding keeps the signature the same but changes the
implementation in a subclass.

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

compile a Java source file ([Link]) into Byte Code?

A. java Example B.

javac [Link]

C. jdb Example D. appletviewer [Link]

o Answer: B. The javac utility is the Java compiler.


9. In the context of a Java program, what is the

scope rule that Java generally follows?

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. Method Overriding B. Constructor Overloading

C. Dynamic Binding D. Type Casting

o Answer: B. This form of overloading allows an object to be initialized in different ways.

Section 2: Advanced OOP, Threads, and Exceptions (Questions 21-


40)
21. What restriction applies when a class

extends an abstract class?

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).

D. It cannot be instantiated unless it is also declared final.

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.

D. Methods must be declared protected; fields must be initialized in the constructor.

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

o Answer: C. Interfaces are implemented, whereas classes are extended (extends).


25. The mechanism that allows a Java application to achieve Multiple Inheritance of Type is through:
A. Using a non-native bridge driver. B. A class implementing multiple interfaces.

C. Declaring all inherited methods as static. D. Nested classes that extend parent functionality.

o Answer: B. A class can implement multiple interfaces (implements Interface1,


Interface2, ...), effectively acquiring multiple types.
26. Which two keywords are mandatory for the basic structure of

Exception Handling in Java?

A. throw and throws B. synchronized and wait C.

try and catch

D. finally and return

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

finally block is guaranteed to execute EXCEPT when:

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]

o Answer: B. Both Exception and Error are subclasses of Throwable.


29. What is the process of defining a

try block inside another try block called?

A. Multiple Catch Blocks B. Exception Delegation C. Nested Try-Catch

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

throws clause in a method signature is to:

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.

D. It eliminates the need for garbage collection.

o Answer: C. Multithreading enables parallelism, reducing overall execution time and


improving resource utilization.
23. What are the two main ways a thread's state can change from

Running to Blocked/Waiting?

A. Using the start() method or finishing the run() method. B. Using the yield() method or
increasing priority. C. Calling

sleep(), wait(), or performing I/O operations.

D. Calling the notify() method or a try-catch block.

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

overridden or implemented to define the execution logic of a thread?

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

join() method on a thread object?

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

join() is called has finished its execution.

D. To add the thread to the highest priority queue.

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:

A. Thread.HIGH_PRIORITY (value 8) B. Thread.NORMAL_PRIORITY (value 5) C.

Thread.MAX_PRIORITY (value 10)

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

16-bit Unicode characters for I/O operations?

A. Byte Stream B. Network Stream C. Character Stream

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

OutputStream or Writer object?

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]()

o Answer: C. The static method [Link]() is used to parse a String into a


primitive int value.

Section 3: GUI, Networking, and Database (Questions 41-60)


41. What is the key difference between an

AWT Frame and an AWT Panel?

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.

D. A Panel is for drawing graphics; a Frame is for text entry.

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: B. The BorderLayout manager uses the five cardinal directions.


44. Which Layout Manager is most appropriate for designing a fixed-size component, such as the grid
for a Tic-Tac-Toe board or a calculator keypad?

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

source of an event in a GUI application?

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

mouseClicked(), mousePressed(), and mouseReleased()?

A. MouseMotionListener B. AWTEventListener C.

MouseListener

D. ComponentListener

o Answer: C. The MouseListener interface handles non-movement mouse actions (clicks,


presses, releases, enters, exits).
47. When an Applet needs external configuration data (input) from its hosting HTML file, which tag is
used in the HTML to supply this data?

A. <param name="..." value="..."/> B. The

<param> tag, which is nested inside the <applet> tag.

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

event that is handled by the KeyListener interface?

A. actionPerformed() B. itemStateChanged() C.
keyTyped()

D. windowClosing()

o Answer: C. The KeyListener handles keyPressed(), keyReleased(), and keyTyped()


events.
50. What is the fundamental difference between the

stop() method and the destroy() method in the Applet lifecycle?

A. stop() halts execution temporarily; destroy() is not guaranteed to execute. B. stop()


temporarily halts execution (when the user leaves the page);

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?

A. DatagramSocket and DatagramPacket B.

ServerSocket and Socket

C. URL and URLConnection D. Thread and Runnable

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

connectionless and sends data in small packets called datagrams is:

A. TCP (Transmission Control Protocol) B. UDP (User Datagram Protocol)

C. HTTP (Hypertext Transfer Protocol) D. SMTP (Simple Mail Transfer Protocol)

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

Connection, Statement, and ResultSet?

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)

C. executeStatement(String sql) D. execute(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?

A. ADD RECORD B. UPDATE C. ALTER TABLE D.

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?

A. DELETE TABLE B. TRUNCATE TABLE C. REMOVE TABLE D.

DROP TABLE

o Answer: D. The DROP TABLE command deletes the table structure and its contents
permanently.

61. What key difference makes

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.,

JTable, JTree) not available in AWT.

D. AWT is platform-independent, while Swing is platform-dependent.

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

JPanel objects and adding the panels to the JFrame.

D. Using a custom LayoutManager for every single component.

o Answer: C. Using multiple JPanels (sub-containers) is standard practice for organized,


hierarchical GUI design.
63. The

CardLayout manager is primarily used to achieve which design effect?

A. Arranging components in a circular pattern. B. Managing multiple components (or panels) in a


stack, where only one is visible at a time.

C. Arranging components in the five regions of a compass. D. Automatically flowing components


from left-to-right, top-to-bottom.

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

.class file cannot be found by the browser?

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

Byte Streams and Character Streams in Java I/O?

A. Byte Streams are platform-independent; Character Streams are platform-dependent. B. Byte


Streams read/write 8-bit bytes; Character Streams read/write 16-bit Unicode characters.

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

limitation of Java Applets?

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.

D. They cannot be executed in a multithreaded manner.

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

Daemon Thread is best described as:

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

ResultSet object named rs?

A. for (int i=0; i < [Link]; i++) B.

while ([Link]())

C. if ([Link]()) D. do { // process } 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:

A. Native Code Interfacing B. Object-Relational Mapping (or bridging two paradigms)

C. Multi-tier Architecture D. Socket-level Communication

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?

A. code B. width C. height D.

codebase

o Answer: D. codebase (location of the class file) is optional;

code, width, and height are mandatory.

74. If a class implements an interface but

fails to define all of the interface's abstract methods, what must that class be declared as?

A. final B. public C.

abstract

D. It will result in a compilation error.


o Answer: C. A class that doesn't implement all inherited abstract methods (from an interface
or abstract class) must itself be declared abstract.
75. What is the equivalent SQL command for the JDBC [Link]("Roll") when retrieving data? A.
INSERT INTO... B. UPDATE... C.

SELECT Roll FROM...

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)

o Answer: C. The standard registration pattern is to use the add...Listener() method


corresponding to the event type.
78. The purpose of the

sleep(long millis) method is to:

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).

D. Assign a lower priority to the current thread.

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?

A. It guarantees that the methods will never throw an InsufficientFundsException. B. It ensures


that both methods are executed sequentially in the same order they were called. C. It prevents two
concurrent threads from modifying the account balance simultaneously, thereby ensuring data
consistency.

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.

[Link] and [Link]

D. [Link] and [Link]

o Answer: C. The legacy I/O classes are in [Link], and the newer, non-blocking I/O classes
are in [Link].

Section 5: Quiz Completion (Questions 81-100)


81. Which type of database management system is primarily managed using

Structured Query Language (SQL)?

A. Object-Oriented Database Management System (OODBMS) B. Relational Database Management


System (RDBMS)

C. Document Database D. Graph Database

o Answer: B. SQL is the standard language for relational databases (RDBMS).


82. The term

'socket' in Java networking refers to:

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.

o Answer: B. A socket is the software abstraction that acts as a unique communication


endpoint.
83. Which of the following is NOT a fundamental type of JDBC driver architecture?

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)

o Answer: D. The four types are 1, 2, 3, and 4.


84. What is the default access level for a class or method member when no modifier is explicitly
provided?

A. public B. protected C. Default (Package-Private)

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.

D. To enable them to be inherited by other interfaces.

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

C. ALTER DATABASE D. SELECT DISTINCT

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

abstract, what does this primarily prevent?

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

DataInputStream, what is the returned data type before conversion?

A. char B. int C. byte D.

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)?

A. Encapsulation B. Inheritance C. Overloading

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.

o Answer: B. public is an access modifier ensuring wide visibility.


92. In a multithreaded environment, if two threads are created in the same way, what determines the
order in which the threads execute?

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.

D. The order in which the Thread objects are declared.

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

super keyword followed by parentheses (super(...)) inside a subclass constructor is to:

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.

C. A NullPointerException is thrown at compile time. D. The Applet automatically switches to a


full Java application mode.

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.

D. It prepares the SQL statement for retrieval.

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

Java Swing package?

A. JTable B. JColorChooser C. JSpinner D. Pointers (Memory Access)

o Answer: D. Java, including Swing, does not support pointers.


98. The mechanism of using a dedicated network of servers to handle many concurrent client requests
(e.g., millions of Gmail users) is an application of:

A. Simple Recursion B. Multithreaded/Distributed Computing

C. Single-Tier Architecture D. Synchronous I/O

o Answer: B. Handling billions of simultaneous users requires powerful multithreaded and


distributed server architecture.
99. When using the

RandomAccessFile class, which method is used to move the file pointer to a specific, arbitrary byte
position within the file?

A. move(int pos) B. skipBytes(int n) C.

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).

Answer: D. A final class cannot serve as a superclass.

You might also like