Constructors are special methods in OOP that are automatically invoked when an object is created. Their primary role is to initialize the object’s attributes and ensure it starts in a valid state.
What does Destructor in OOP typically do?
A Release resources
B Overload method
C Clone object
D Initialize object
Destructors are special methods called when an object is destroyed. They are responsible for releasing any resources (like memory or file handles) that the object was using, helping prevent memory leaks.
What is the purpose of Access Modifiers in OOP?
A Increase security
B Store data
C Control visibility
D Clone objects
Access modifiers (e.g., public, private, protected) are used to control the visibility and accessibility of class members (methods and attributes) from outside the class, ensuring proper encapsulation and data protection.
Which binding is resolved at compile time in OOP?
A Late
B Dynamic
C Static
D Early
Static binding, also known as early binding, occurs at compile time. The method to be invoked is determined by the compiler based on the reference type, offering faster execution but less flexibility.
Which binding is resolved at runtime in OOP?
A Late
B Dynamic
C Early
D Static
Dynamic binding occurs at runtime and is used in polymorphic method calls. The actual method to be invoked is determined based on the object type, not the reference type, allowing for flexible method resolution.
Which method allows a class to inherit properties from another class in OOP?
A Abstraction
B Polymorphism
C Inheritance
D Encapsulation
Inheritance allows a class (subclass) to inherit properties and methods from another class (superclass), promoting code reuse and establishing relationships between classes. This forms the foundation for many OOP systems.
Which concept allows the same method name to behave differently based on input?
A Overloading
B Inheritance
C Cloning
D Overriding
Method overloading allows a class to define multiple methods with the same name but different parameters. The correct method is chosen based on the number or type of arguments passed to it.
What does Method Overriding allow in OOP?
A Avoid inheritance
B Change inherited method
C Clone objects
D Prevent access
Method overriding allows a subclass to provide its own implementation of a method inherited from the superclass. This is essential for customizing or extending inherited behavior to suit the subclass’s needs.
Which OOP principle ensures that classes can interact with each other through interfaces?
A Inheritance
B Encapsulation
C Abstraction
D Polymorphism
Abstraction hides complex implementation details and exposes only necessary parts of the system. Interfaces in OOP define contracts that allow classes to communicate without exposing the underlying implementation, fostering loose coupling.
Which of the following is true for Abstract Classes in OOP?
A Have abstract methods
B Must be inherited
C Cannot be instantiated
D All of the above
Abstract classes cannot be instantiated directly. They are intended to be inherited by subclasses. They may contain abstract methods (without implementations), which must be implemented by the subclasses to complete the functionality.
What is the role of Interfaces in OOP?
A Manage memory
B Provide method signatures
C Create objects
D Implement functionality
Interfaces define a set of method signatures without providing implementations. Classes that implement an interface must provide their own implementation for the methods, ensuring that they adhere to the specified contract.
Which OOP design pattern ensures that only one instance of a class is created?
A Factory
B Observer
C Builder
D Singleton
The Singleton pattern ensures that only one instance of a class exists throughout the system. It provides a global point of access to this instance, preventing the creation of multiple instances and optimizing resource usage.
What is the main purpose of Exception Handling in OOP?
A Prevent crashes
B Control object state
C Reuse code
D Optimize performance
Exception handling in OOP allows the program to catch and manage errors during runtime without crashing. By using try, catch, and finally blocks, developers can control how errors are handled and ensure program stability.
Which technique helps in managing resources like memory in OOP?
A Exception Handling
B Event Handling
C Method Overloading
D Garbage Collection
Garbage collection automatically reclaims memory occupied by objects that are no longer in use. This process helps in managing memory efficiently, preventing memory leaks and ensuring optimal performance in OOP‐based applications.
Which design pattern is used for creating objects without specifying the exact class?
A Prototype
B Factory
C Builder
D Singleton
The Factory design pattern allows objects to be created without specifying the exact class of the object. The factory method abstracts the object creation process and returns instances based on the given parameters or conditions.