Computer Knowledge
Object-Oriented Programming
2,686 Questions
Object-oriented programming questions test core computer science concepts like classes, inheritance, polymorphism, and encapsulation. The focus includes Java program structures, method overloading, and memory allocation for objects. This topic is essential for technical sections in various recruitment tests.
Java class definitionsMethod overriding rulesPolymorphism conceptsGeneric type parametersMemory allocation in objects
Object-Oriented Programming Questions
Which software design pattern is used to provide a uniform interface to a set of related objects?
-
Factory Method
-
Singleton
-
Facade
-
Builder
C
Correct answer
Explanation
The Facade design pattern is used to provide a uniform interface to a set of related objects.
What is a complexity class?
-
A set of problems that can be solved by a Turing machine in a certain amount of time.
-
A set of problems that can be solved by a Turing machine in a certain amount of space.
-
A set of problems that can be solved by a Turing machine in a certain number of steps.
-
A set of problems that can be solved by a Turing machine in a certain amount of memory.
A
Correct answer
Explanation
A complexity class is a set of problems that can be solved by a Turing machine in a certain amount of time. The most common complexity classes are P, NP, and EXPTIME.
Which design pattern is used to define a family of related objects?
-
Factory Method
-
Singleton
-
Strategy
-
Abstract Factory
D
Correct answer
Explanation
The Abstract Factory pattern provides an interface for creating families of related objects without specifying their concrete classes.
Which design pattern is commonly used to implement the Observer pattern?
-
Adapter
-
Composite
-
Decorator
-
Publisher-Subscriber
D
Correct answer
Explanation
The Publisher-Subscriber pattern defines a one-to-many dependency between objects, where one object (publisher) notifies multiple objects (subscribers) about changes in its state.
Which design pattern is used to provide a unified interface to a set of related classes?
-
Facade
-
Proxy
-
Adapter
-
Composite
A
Correct answer
Explanation
The Facade pattern provides a unified interface to a set of related classes, simplifying their use and reducing coupling.
Which design pattern is commonly used to implement the Singleton pattern?
-
Factory Method
-
Singleton
-
Strategy
-
Abstract Factory
B
Correct answer
Explanation
The Singleton pattern ensures that a class has only one instance and provides a global point of access to that instance.
Which of the following is NOT a common section found in API documentation?
-
Introduction
-
Function reference
-
Class reference
-
Troubleshooting guide
D
Correct answer
Explanation
A troubleshooting guide is not typically a common section found in API documentation. It is more commonly found in user manuals or technical documentation, where it provides tips and solutions for common issues and problems.
What is an initial object in a category?
-
An object with a unique morphism from every other object
-
An object with a unique morphism to every other object
-
An object with no incoming morphisms
-
An object with no outgoing morphisms
A
Correct answer
Explanation
An initial object in a category is an object that has a unique morphism from every other object in the category, representing a universal starting point.
What is a terminal object in a category?
-
An object with a unique morphism from every other object
-
An object with a unique morphism to every other object
-
An object with no incoming morphisms
-
An object with no outgoing morphisms
B
Correct answer
Explanation
A terminal object in a category is an object that has a unique morphism to every other object in the category, representing a universal ending point.
Which design pattern is used to define a family of algorithms, encapsulate each one, and make them interchangeable?
-
Factory Method
-
Strategy
-
Observer
-
Singleton
B
Correct answer
Explanation
The Strategy pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. This lets the algorithm vary independently from clients that use it.
What is the purpose of the Observer design pattern?
-
To define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
-
To create a single instance of a class and provide a global point of access to that instance.
-
To provide a way to add or remove objects from a collection dynamically.
-
To define an interface for creating objects, but let subclasses decide which class to instantiate.
A
Correct answer
Explanation
The Observer pattern defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
Which design pattern is used to create a single instance of a class and provide a global point of access to that instance?
-
Factory Method
-
Strategy
-
Observer
-
Singleton
D
Correct answer
Explanation
The Singleton pattern ensures that a class has only one instance and provides a global point of access to that instance.
What is the purpose of the Factory Method design pattern?
-
To define a family of algorithms, encapsulate each one, and make them interchangeable.
-
To create a single instance of a class and provide a global point of access to that instance.
-
To provide a way to add or remove objects from a collection dynamically.
-
To define an interface for creating objects, but let subclasses decide which class to instantiate.
D
Correct answer
Explanation
The Factory Method pattern defines an interface for creating objects, but lets subclasses decide which class to instantiate.
What is the purpose of the Adapter design pattern?
-
To convert the interface of a class into another interface clients expect.
-
To define a family of algorithms, encapsulate each one, and make them interchangeable.
-
To provide a way to add or remove objects from a collection dynamically.
-
To define an interface for creating objects, but let subclasses decide which class to instantiate.
A
Correct answer
Explanation
The Adapter pattern converts the interface of a class into another interface clients expect. This lets classes work together that couldn't otherwise because of incompatible interfaces.
Which design pattern is used to define a family of related classes and provide a way to create objects without specifying their exact class?
-
Factory Method
-
Abstract Factory
-
Builder
-
Prototype
B
Correct answer
Explanation
The Abstract Factory pattern provides an interface for creating families of related objects without specifying their concrete classes.