Encapsulation is a fundamental OOP principle that involves bundling data and the methods that operate on that data within a single unit or class. This helps in hiding the internal state of the object from the outside world, promoting data hiding and increasing security.
Which of the following is a key feature of Polymorphism?
A Method Overloading
B Constructor
C Abstraction
D Data hiding
Polymorphism allows objects of different classes to be treated as objects of a common superclass. It is commonly implemented through method overloading, where multiple methods with the same name exist but with different parameters.
What does Inheritance allow in OOP?
A Data hiding
B Secure coding
C Event handling
D Reusability
Inheritance enables a new class (subclass) to acquire properties and behaviors (methods) from an existing class (superclass), facilitating code reusability and making it easier to maintain and extend existing code.
What is the purpose of a Constructor in OOP?
A Exception handling
B Object initialization
C Memory management
D Method overloading
A constructor is a special type of method that is automatically called when an object of a class is created. Its main purpose is to initialize the object’s state by assigning initial values to its attributes.
Which of the following is a feature of Abstraction?
A Reusability
B Polymorphism
C Hiding implementation details
D Security
Abstraction allows the user to focus on essential functionalities while hiding the complex implementation details. It simplifies interaction by exposing only necessary parts and concealing the unnecessary internal workings of an object.
What does Static Binding refer to in OOP?
A Runtime binding
B Exception handling
C Object initialization
D Compile-time binding
Static binding (or early binding) occurs at compile time when the method to be invoked is determined. It is more efficient because it doesn’t require runtime evaluation, unlike dynamic binding, which is resolved at runtime.
Which of the following concepts allows a class to inherit from more than one class?
A Abstraction
B Multiple Inheritance
C Encapsulation
D Polymorphism
Multiple inheritance allows a class to inherit features from more than one class, enabling the subclass to combine the attributes and methods of its parent classes. However, it is not directly supported in many programming languages like Java.
What is an Abstract Class in OOP?
A A class that cannot be inherited
B A class that is a singleton
C A class with at least one abstract method
D A class with no objects
An abstract class is a class that cannot be instantiated directly. It can contain abstract methods (methods without implementation) which must be implemented by its subclasses, providing a blueprint for derived classes.
Which of these is NOT a principle of OOP?
A Modularity
B Abstraction
C Inheritance
D Encapsulation
While modularity is an important concept in software engineering, it is not one of the core principles of OOP. The core principles are encapsulation, inheritance, polymorphism, and abstraction, which help in organizing and structuring code.
Method Overloading allows:
A Same method, same signature
B Same method name, different signature
C Method overriding
D Different method names, same signature
Method overloading allows you to define multiple methods with the same name but different parameter types or numbers of parameters. This enables a method to perform similar operations with different inputs.
Which of the following is an interface in OOP?
A Abstract method
B Collection
C A contract for classes to follow
D Class
An interface defines a contract for what methods a class must implement but does not provide implementation itself. It allows different classes to implement the same methods in different ways, promoting flexibility and interoperability.
What is Dynamic Binding?
A Creating object instances
B Binding to a static class
C Resolving method calls at compile-time
D Resolving method calls at runtime
Dynamic binding, or late binding, occurs when the method to be called is determined at runtime based on the actual object type, not the reference type. It allows for more flexible and dynamic behavior in object-oriented systems.
What does Exception Handling provide in OOP?
A Error detection and recovery
B Object cloning
C Memory management
D Method overloading
Exception handling in OOP allows for the detection and management of runtime errors. It helps in recovering from errors gracefully by using constructs like try, catch, and finally to handle exceptions and maintain program flow.
What is the main advantage of Object Cloning?
A Exception handling
B Reusability
C Creating identical copies
D Memory optimization
Object cloning refers to creating an exact copy of an object. This allows for efficient duplication of objects with identical states, which is useful in cases where creating new instances based on existing ones is required.
What does SOLID stand for in OOP?
A Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion
B Secure Open Liskov Interface Dependency
C Simple Object-Oriented Logic Integration Design
D Secure Object-oriented Logic for Integrated Development
SOLID is an acronym for five design principles that help improve the design, readability, and maintainability of object-oriented systems. These principles ensure the system is scalable, flexible, and easier to maintain.