NEW
Font size
Worksheetsoop final
Total questions: 40
Worksheet time: 20mins
How many types of design patterns are there?
3
5
8
10
What is the main benefit of using a design pattern?
It reduces the total codebase
It allows for the separation of responsibilities
It ensures that the code is easier to understand and debug
All of the above
Which of the following is NOT a creational design pattern?
Singleton Pattern
Factory Pattern
Bridge Pattern
Prototype Pattern
Which of the following is a behavioral design pattern?
Observer Pattern
Composite Pattern
Flyweight Pattern
Builder Pattern
What is a Singleton design pattern?
A design pattern that allows you to ensure that a class has only one instance
A design pattern that lets you fit more objects into the available amount of RAM
A design pattern that separates an object's specification from its implementation
A design pattern that ensures that the class has multiple instances
Which of the following best describes the Factory Pattern in design patterns?
It is used to create duplicate objects while keeping performance in mind.
It involves a single class that is responsible to join functionalities of independent or incompatible interfaces.
It involves a single class that is responsible to join functionalities of independent or incompatible interfaces.
It allows an object to be created without exposing the creation logic to the client and the created object is referred to using a common interface.
What is the use of the Builder Pattern?
It simplifies the creation of complex objects by breaking the creation process into steps.
It allows an object to alter its behavior when its internal state changes.
It ensures a class has only one instance and provides a global point of access to it.
It helps in hiding the complexities of the system and provides an interface to the client.
What is Template Design Pattern?
It defines the skeleton of an algorithm in a method, deferring some steps to subclasses.
It ensures that a class has only one instance and provides a global point of access to it.
It encapsulates a request as an object, thereby allowing for the parameterization of clients with queues, requests, and operations.
t provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation
Which package is primarily used for JDBC classes and interfaces?
java.sql
java.db
java.jdbc
java.database
Which interface handles the result of a query?
QuerySet
DbResult
ResultSet
QueryResult
What is the purpose of Run-Time Type Identification (RTTI) in Java?
To allow a program to generate types at runtime
To enable a Java program to identify and access the type of an object at runtime
To prevent type errors in a program at compile time
To increase the runtime efficiency of a program
What do Java Generics allow programmers to do?
Create classes that are not type-safe.
Specify, with a single method declaration, a set of related methods.
Avoid the use of the instanceof operator.
Increase the runtime overhead of a program.
Which of the following best describes lambda expressions in Java?
A feature that allows the creation of anonymous classes only.
A way to implement interfaces with multiple abstract methods.
An anonymous method that can be used to implement methods defined in a functional interface.
A tool used exclusively for collection manipulation.
What characterizes static methods in interfaces?
They can be overridden by implementing classes.
They do not require an instance of the interface to be invoked.
They are implemented to provide default behavior for all implementing classes.
They increase the runtime overhead due to dynamic binding.
Which operator is used with RTTI to check if an object is an instance of a specific class?
==
.equals()
instanceof
getClass()
Which method is used to obtain a reference to the Class object in Reflection?
getClass()
getType()
newInstance()
getMethod()
Is design pattern a logical concept.
True
False
How many abstract methods can a functional interface have?
One
Two
As many as needed
None
How are lambda expressions compiled in Java?
Into anonymous inner classes
Into regular methods of the class where they are defined
Using a special lambda compiler
Into instances of functional interfaces
What does the executeQuery() method of the Statement interface return?
An integer
A boolean
ResultSet
PreparedStatement
Which type of polymorphism is achieved by method overriding?
Compile-time Polymorphism
Runtime Polymorphism
Operator Polymorphism
Class Polymorphism
What is method overriding?
Changing the value of a method's parameters in the subclass
Defining a method in the subclass that is already defined in the parent class with a different implementation
Increasing the visibility of a method in a subclass
Reducing the visibility of a method in a subclass
Polymorphism in object-oriented programming is the ability to treat objects of any subclass as if they were objects of the superclass.
True
False
An abstract class in Java can be instantiated directly.
True
False
Method Overloading is a type of Runtime Polymorphism.
True
False
Polymorphism in Java is limited to the use of interfaces.
True
False
Which blocks are used to handle exceptions in Java?
if-else blocks
try-catch blocks
switch-case blocks
for-while blocks
What does JDBC stand for?
Java Database Connectivity
Java Data Connection Base
Java Development Connection Bridge
Java Direct Class Base
Exception handling in Java is designed to handle runtime errors, allowing the program to continue executing.
True
False
The finally block is executed only if no exceptions are thrown within the try block.
True
False
A single method in Java can throw multiple types of exceptions.
True
False
You must install the JDBC API explicitly to use it in your projects.
True
False
What is the purpose of try-catch in Java?
To handle compile-time errors
To handle runtime exceptions
To improve code performance
To terminate the program
Which method is used to execute an SQL query in JDBC?
executeQuery()
executeUpdate()
execute()
executeBatch()
Which keyword is used to throw an exception explicitly in Java?
Throw
Catch
Try
Finally
What distinguishes the Factory Method Design Pattern from other Creational Patterns?
It allows classes to defer instantiation to subclasses.
It ensures that a class has only one instance.
It focuses on building complex objects step by step.
It is primarily used for object cloning.
Which of these is a valid lambda expression in Java?
x, y -> x + y
(x, y) -> x + y
(x, y) => x + y
(x + y)
What does polymorphism mean in the context of object-oriented programming?
The ability of different classes to respond to the same function call
The process of converting a superclass type to a subclass type
A programming technique that involves many forms of loops
The method of creating multiple classes from a single class
What is an abstract class in Java?
A class that cannot be instantiated and is designed to be a superclass
A class that can be instantiated and used directly
A final class that cannot be extended
A class without any methods
What does upcasting refer to?
Casting a subclass type to a superclass type
Casting a superclass type to a subclass type
Casting between unrelated classes
Casting within the same class type
