Abstraction focuses on showing only the essential features and hiding the complex implementation details of an object. It simplifies the interaction by providing a high-level interface while concealing the complexity.
Which of the following best describes Polymorphism?
A Same method, different signatures
B Multiple classes, one object
C Reusability of code
D Same name, different behavior
Polymorphism allows the same method name to behave differently based on the object calling it. It is achieved through method overriding and dynamic method dispatch, providing flexibility in code execution.
Which OOP principle uses private variables and public methods to ensure safe data handling?
A Polymorphism
B Encapsulation
C Inheritance
D Abstraction
Encapsulation is about wrapping data (variables) and the methods that operate on that data within one unit (class). It restricts direct access to some of an object’s components to prevent accidental modification and protect the data.
What does Inheritance promote in OOP?
A Data hiding
B Method overriding
C Code reuse
D Code complexity
Inheritance allows a new class to inherit properties and behaviors from an existing class. This promotes code reuse, as common functionality can be shared across different classes, reducing redundancy and simplifying maintenance.
Which concept allows multiple methods to have the same name but different parameters?
A Method Overloading
B Abstraction
C Method Overriding
D Polymorphism
Method overloading allows a class to have multiple methods with the same name but different parameter types or numbers. This allows the same method name to be used for different purposes based on inputs.
What does Object Cloning provide in OOP?
A Inheritance behavior
B Memory optimization
C Creating duplicate objects
D Code modularity
Object cloning allows for creating an exact copy of an existing object. This is useful when you need to duplicate an object’s state without creating a new instance, ensuring identical objects for specific tasks.
What type of method does Method Overriding modify?
A Private method
B Constructor
C Abstract method
D Inherited method
Method overriding occurs when a subclass provides its own implementation of a method that it inherits from the superclass. It allows subclasses to modify or extend the behavior of inherited methods to meet specific requirements.
Which of the following allows an object to inherit both data and behavior?
A Encapsulation
B Inheritance
C Abstraction
D Polymorphism
Inheritance allows a new class (child class) to inherit both data (attributes) and behavior (methods) from an existing class (parent class). This enables reuse of code and promotes a hierarchical class structure.
Which OOP principle involves hiding the complexity of an object from the outside world?
A Abstraction
B Polymorphism
C Encapsulation
D Inheritance
Abstraction hides the complex internal workings of an object and only exposes necessary functionalities. It simplifies interactions with objects, allowing users to focus on high-level behavior rather than implementation details.
What is a key feature of Abstract Classes in OOP?
A Always use constructors
B Can only contain methods
C Cannot be instantiated
D Must have static methods
An abstract class cannot be instantiated on its own. It serves as a blueprint for other classes. Abstract methods within the class must be implemented by subclasses, but the abstract class itself is incomplete.
Which access modifier allows access to class members from anywhere in the program?
A Polymorphism
B Abstraction
C Default
D Public
The public access modifier allows class members (attributes or methods) to be accessed from any other class in the program, making them widely accessible to other components and classes in the system.
What does Static Binding occur at?
A Object initialization
B Runtime
C Compile time
D Method overriding
Static binding occurs at compile time, where the method or function calls are resolved based on the method signatures. This is contrasted with dynamic binding, which is resolved at runtime depending on the object type.
What is the main advantage of Interfaces in OOP?
A Establish a contract for classes
B Promote inheritance
C Provide default implementations
D Reduce code complexity
Interfaces define a contract that specifies which methods a class must implement. This allows different classes to implement the same interface in different ways, promoting flexibility and ensuring consistent method availability.
Which of the following is an example of Design Patterns in OOP?
A Constructor
B Object cloning
C Singleton
D Abstract method
The Singleton design pattern ensures that a class has only one instance and provides a global point of access to that instance. It is commonly used when only one object should manage resources, like a connection pool.
What is the main purpose of Exception Handling in OOP?
A Code optimization
B Handling runtime errors
C Object cloning
D Dynamic method dispatch
Exception handling is used to manage runtime errors. By using try-catch blocks, it ensures that errors are handled gracefully, preventing program crashes and providing a way to manage abnormal situations during program execution.