Q: What role do objects play in OOP?
-
A
They serve as static data structures.
-
B
They act as instances of classes that encapsulate data and behavior.
-
C
They eliminate the need for classes.
-
D
They enforce global state management.
B
Answer:
B
Explanation:
In object-oriented programming, objects are the fundamental building blocks that represent instances of classes. Each object encapsulates data (attributes) and behavior (methods) defined by its class, allowing for the creation of complex and modular software systems. Objects interact with one another through methods, which operate on the data encapsulated within the objects. This encapsulation of data and behavior within objects promotes modularity and reusability, as objects can be reused across different parts of the application without requiring changes to their internal implementation. Objects also support inheritance and polymorphism, which allow for the creation of hierarchical relationships and flexible method invocation, respectively. By modeling real-world entities as objects, OOP provides a more intuitive and natural way to design and build software systems.
Related Topic:
Share Above MCQ