Code reusability in OOP promotes creating modular, reusable components such as classes and methods. By reusing code, developers avoid duplication, making the codebase easier to maintain and extend without rewriting existing functionality.
Which of the following is an advantage of Object Cloning in OOP?
A Copies an object
B Optimizes runtime
C Increases inheritance
D Reduces memory usage
Object cloning in OOP allows creating an exact copy of an object. This is useful when an object’s state needs to be duplicated without affecting the original object, making it easier to work with similar objects independently.
Which OOP concept involves creating a new instance by copying an existing object?
A Abstraction
B Inheritance
C Object Cloning
D Polymorphism
Object cloning creates a copy of an object by duplicating its state. It is often used when the state of the original object needs to be preserved, and a new instance is needed for further manipulation or processing.
What does Dynamic Method Dispatch allow in OOP?
A Memory management
B Runtime method resolution
C Static method calls
D Object initialization
Dynamic method dispatch is the process by which a method is called at runtime based on the object type rather than the reference type. This allows for method calls to resolve dynamically in polymorphic scenarios, enabling flexibility in method invocation.
Which feature of Polymorphism allows different classes to have the same method name?
A Dynamic binding
B Method Overloading
C Method Overriding
D Constructor Overloading
Method overriding allows subclasses to provide specific implementations of a method already defined in the superclass. This enables polymorphism, allowing different classes to use the same method name but behave differently based on the object’s type.
What is the benefit of Dynamic Method Dispatch in polymorphism?
A Improves memory management
B Faster execution
C Provides runtime method selection
D Resolves methods at compile time
Dynamic method dispatch allows the method to be resolved at runtime based on the actual object type, not the reference type. This is key in implementing polymorphism, where the same method behaves differently depending on the object that calls it.
What is Code Reusability primarily achieved through in OOP?
A Inheritance
B Exception Handling
C Object Cloning
D Method Overloading
Inheritance enables code reusability by allowing a new class to inherit properties and methods from an existing class. This prevents redundant code and facilitates easier maintenance and extension of functionality in new classes.
What does Object Cloning ensure when copying an object?
A Prevents inheritance
B Copies both data and methods
C Copies constructor only
D Copies methods only
Object cloning creates a new instance that is an exact copy of the original object, including both data (attributes) and methods. It ensures that the new object has the same state and behavior as the original one.
Which of the following is an example of Dynamic Method Dispatch in OOP?
A Creating a method in a superclass
B Using method overloading
C Calling a method based on object type at runtime
D Calling a method based on reference type at compile time
Dynamic method dispatch is the process where a method call is resolved at runtime based on the actual object type. This allows polymorphic behavior, enabling the correct method to be invoked based on the object that is used.
Which of the following best describes Polymorphism in OOP?
A Same method, multiple forms
B Multiple classes, one method
C Same object, different state
D Multiple objects, one class
Polymorphism allows the same method name to perform different tasks based on the object that invokes it. It can be achieved through method overriding or overloading, enabling different behaviors under the same method name.
Which of the following principles is most closely related to Code Reusability in OOP?
A Abstraction
B Inheritance
C Encapsulation
D Polymorphism
Inheritance allows classes to reuse code from other classes. A subclass can inherit methods and properties from a superclass, promoting code reuse and reducing redundancy, which makes maintenance and modification easier.
What does Method Overloading allow in OOP?
A A method in one class and another in a subclass
B Multiple classes with the same name
C A method with the same signature
D Multiple methods with the same name
Method overloading allows multiple methods to share the same name but differ in parameters (type, number, or both). This enhances flexibility, allowing the method to perform different tasks based on the arguments passed to it.
What is the key difference between Object Cloning and Object Instantiation?
A Instantiation is more efficient than cloning
B Cloning creates a new object
C Instantiation initializes the object’s class
D Cloning copies data from an object
Object cloning creates an exact copy of an existing object, including both data and methods. Object instantiation, on the other hand, creates a new object from a class without copying data from any existing object.
What does Polymorphism allow a subclass to do in OOP?
A Inherit multiple classes
B Define static methods
C Override or extend inherited methods
D Hide methods in subclasses
Polymorphism allows a subclass to override or extend methods from its superclass. This provides flexibility, enabling subclasses to modify inherited behavior while keeping the same method signature, which is useful for method customization.
Which OOP concept helps to ensure that an object’s state is not directly modified?
A Inheritance
B Encapsulation
C Method Overloading
D Polymorphism
Encapsulation is the principle of bundling an object’s data (attributes) and methods that operate on that data into a single unit, while restricting direct access to the internal state. This protects data integrity by controlling how it is modified.