Object serialization converts an object’s state into a byte stream, which can then be written to a file or sent over a network. This allows objects to be saved and later restored, facilitating persistence and communication.
Which of the following is a key benefit of Object Serialization?
A Data persistence
B Code optimization
C Dynamic binding
D Method overriding
Object serialization helps maintain the state of an object by converting it into a format that can be stored or transmitted. It allows for data persistence, so objects can be restored even after the application ends or restarts.
Which of the following SOLID principles focuses on reducing the impact of changes in a class?
A Interface Segregation Principle
B Single Responsibility Principle
C Open/Closed Principle
D Liskov Substitution Principle
The Open/Closed Principle states that a class should be open for extension but closed for modification. This allows for easier maintenance and scalability, as changes to behavior can be made by extending the class, not modifying it.
Which SOLID principle emphasizes that a class should have only one reason to change?
A Liskov Substitution Principle
B Dependency Inversion Principle
C Single Responsibility Principle
D Interface Segregation Principle
The Single Responsibility Principle (SRP) advocates that a class should only have one responsibility or reason to change. This reduces complexity, enhances code maintainability, and makes the system more modular.
What does UML (Unified Modeling Language) primarily help to do in OOP?
A Handle runtime exceptions
B Visualize system architecture
C Create dynamic behavior
D Define class attributes
UML is a standardized modeling language used to visualize, specify, and document the structure and behavior of a system. It provides various diagrams (like class and sequence diagrams) to represent different aspects of a system.
Which UML diagram is used to represent the structure of classes and their relationships?
A Sequence diagram
B Activity diagram
C Class diagram
D Use case diagram
A class diagram in UML represents the structure of a system by showing its classes, their attributes, methods, and the relationships between them. It is one of the most commonly used diagrams in object‐oriented design.
What is the purpose of Method Overriding in OOP?
A To change inherited methods
B To reduce code complexity
C To create new methods
D To optimize method calls
Method overriding allows a subclass to provide its own implementation for a method that is already defined in its superclass. This enables behavior customization, ensuring that the subclass can adapt the inherited method to its needs.
Which of the following is an example of Polymorphism in OOP?
A Data encapsulation
B Method Overloading
C Object serialization
D Inheritance
Polymorphism in OOP allows the same method name to perform different tasks depending on the input. Method overloading is an example where multiple methods with the same name are defined, but they differ in parameters or type.
Which SOLID principle ensures that clients should not be forced to depend on interfaces they do not use?
A Single Responsibility Principle
B Open/Closed Principle
C Interface Segregation Principle
D Dependency Inversion Principle
The Interface Segregation Principle states that no client should be forced to depend on interfaces it does not use. This encourages the design of smaller, more specific interfaces, making code more maintainable and flexible.
In UML, which diagram helps to depict the dynamic flow of a system through interaction between objects?
A State diagram
B Sequence diagram
C Class diagram
D Use case diagram
A sequence diagram in UML illustrates how objects interact in a particular scenario of a use case. It shows the order of method calls, message passing, and the sequence of events that occur during runtime.
Which of the following principles states that a subclass must be substitutable for its superclass?
A Liskov Substitution Principle
B Single Responsibility Principle
C Interface Segregation Principle
D Dependency Inversion Principle
The Liskov Substitution Principle states that objects of a superclass should be replaceable with objects of a subclass without affecting the correctness of the program. This ensures that subclasses maintain the behavior expected of the superclass.
Which UML diagram helps in understanding user interactions with a system?
A Component diagram
B State diagram
C Activity diagram
D Use case diagram
A use case diagram in UML is used to represent the functional requirements of a system. It illustrates how users (actors) interact with the system, defining the system’s boundaries and showing the relationships between users and use cases.
Which of the following is NOT a benefit of applying SOLID principles in OOP?
A Code flexibility
B Code maintainability
C Increased complexity
D Easier debugging
The SOLID principles are designed to improve code maintainability, flexibility, and readability while reducing complexity. Following SOLID principles makes code easier to modify, test, and extend, rather than making it more complex.
In UML, which diagram is used to show the flow of activities and actions in a system?
A Class diagram
B Sequence diagram
C Use case diagram
D Activity diagram
An activity diagram in UML shows the dynamic aspects of a system by representing the flow of control or data from one activity to another. It is useful for modeling business processes or workflows in a system.
What is the main role of Object Serialization in distributed systems?
A Execute remote calls
B Convert object to byte stream
C Compress data
D Store data in files
In distributed systems, object serialization converts an object into a byte stream, allowing it to be transmitted over a network or stored. This is essential for object persistence and enabling communication between distributed components.