1.What is the purpose of using exception handling in a Library Management System?
A) To improve the performance of the system
B) To gracefully handle unexpected errors or situations
C) To reduce the complexity of the code
D) To enhance user interface design
Answer: B) To gracefully handle unexpected errors or situations
Explanation: Exception handling allows developers to anticipate and handle unexpected errors that might occur during program execution, ensuring that the system can handle errors gracefully without crashing.
2.Which of the following data structures is commonly used for implementing a book catalog in a Library Management System?
A) Stack
B) Queue
C) Array
D) HashMap
Answer: D) HashMap
Explanation: HashMap provides efficient key-value pair storage, making it suitable for implementing a book catalog where books can be indexed by unique identifiers such as ISBN numbers.
3.In Java, which keyword is used to define a new thread?
A) start
B) new
C) thread
D) run
Answer: B) new
Explanation: The new keyword is used to instantiate a new thread object in Java.
4.What is the purpose of the synchronized keyword in Java multi-threading?
A) To pause a thread’s execution
B) To specify a block of code that can be executed by only one thread at a time
C) To terminate a thread
D) To start a new thread
Answer: B) To specify a block of code that can be executed by only one thread at a time
Explanation: The synchronized keyword is used to create a mutually exclusive block of code, ensuring that only one thread can execute it at a time, preventing concurrent access issues.
5.Which of the following is NOT a valid method for handling strings in Python?
A) concatenation
B) slicing
C) parsing
D) interpolation
Answer: C) parsing
Explanation: Parsing is not a method for handling strings in Python. It refers to the process of analyzing a string to determine its grammatical structure.
6.What does the method strip() do in Python string manipulation?
A) Removes all occurrences of a specified character from the beginning and end of a string
B) Removes leading and trailing whitespace from a string
C) Splits a string into substrings based on a specified delimiter
D) Returns the length of the string
Answer: B) Removes leading and trailing whitespace from a string
Explanation: The strip() method in Python removes any leading (spaces at the beginning) and trailing (spaces at the end) characters (space is the default leading character to remove).
7.Which exception is raised when trying to access a key that does not exist in a Python dictionary?
A) KeyError
B) ValueError
C) IndexError
D) SyntaxError
Answer: A) KeyError
Explanation: In Python, a KeyError is raised when trying to access a key that doesn’t exist in a dictionary.
8.Which of the following is NOT a valid method for iterating over elements in a Python list?
A) for loop
B) while loop
C) map function
D) iter function
Answer: C) map function
Explanation: The map() function in Python applies a given function to each item of an iterable (like a list) and returns a list of the results. It is not used for iteration over elements.
9.What is the purpose of the join() method in Python string manipulation?
A) Splits a string into substrings based on a specified delimiter
B) Concatenates strings together
C) Returns the length of the string
D) Converts all characters in a string to uppercase
Answer: B) Concatenates strings together
Explanation: The join() method in Python concatenates strings together using a specified separator.
10.Which of the following data structures would be most suitable for implementing a list of borrowed books in a Library Management System?
A) LinkedList
B) Set
C) Array
D) Stack
Answer: A) LinkedList
Explanation: LinkedList provides dynamic memory allocation and can efficiently handle insertion and deletion of elements, making it suitable for maintaining a list of borrowed books which can change dynamically.