Dynamic Method Dispatch is the mechanism by which a method call is resolved at runtime based on the actual object type, not the reference type. This allows polymorphic behavior and flexibility in method invocation.
Which of the following best describes Event-Driven Programming in OOP?
A Methods are called sequentially
B Memory management is handled automatically
C Program flow depends on user events
D Code executes in a specific order
Event-driven programming is a paradigm where the flow of the program is determined by events such as user actions (clicks, keystrokes) or system-generated events. It is widely used in GUI and interactive applications.
Which OOP concept allows an object’s method to be determined at runtime?
A Dynamic Method Dispatch
B Static Binding
C Method Overriding
D Method Overloading
Dynamic Method Dispatch allows a method to be called based on the object’s actual type during runtime. This is key for polymorphism, where the same method can behave differently depending on the object invoking it.
What is the main focus of Secure Coding in OOP?
A Improving code readability
B Enhancing system performance
C Preventing security vulnerabilities
D Reducing code size
Secure coding in OOP involves writing code that is resistant to attacks, such as injection attacks, buffer overflows, and unauthorized data access. It focuses on safe data handling, input validation, and proper exception handling to protect applications.
Which technique is commonly used to handle errors securely in OOP?
A Polymorphism
B Exception Handling
C Memory Management
D Dynamic Binding
Exception handling in OOP helps catch errors at runtime and manage them in a controlled way. Using try, catch, and finally blocks, it allows programs to handle unforeseen errors without crashing, ensuring secure error recovery.
Which concept in OOP is responsible for ensuring data is protected from unauthorized access?
A Polymorphism
B Inheritance
C Encapsulation
D Abstraction
Encapsulation helps protect an object’s internal state by restricting access to its data. This is achieved by using access modifiers like private or protected and exposing data through public getter and setter methods, enhancing security and control.
In event-driven programming, what triggers a system response?
A File input/output operations
B User or system-generated events
C Object instantiation
D System resource allocation
In event-driven programming, the flow of execution is determined by events. These events could be user actions like clicking a button or system-generated signals like receiving data. The system responds by invoking event handlers.
Which of the following is an example of Secure Coding in OOP?
A Using prepared statements for database queries
B Inheriting from abstract classes
C Dynamic object creation
D Using method overloading
Using prepared statements for database queries is a secure coding practice to prevent SQL injection attacks. It ensures that user input is safely handled and does not interfere with SQL query execution.
Which technique is used to ensure that an object’s state cannot be modified directly?
A Abstraction
B Polymorphism
C Encapsulation
D Inheritance
Encapsulation restricts direct access to an object’s internal state and only allows modification through controlled methods (getters and setters). This prevents unauthorized changes and ensures the object’s state remains valid and secure.
What is the primary use of Event Handlers in OOP?
A Optimize code performance
B Respond to events triggered by the user or system
C Store data from user input
D Manage error handling
Event handlers in OOP are used to respond to user or system-generated events. For example, in GUI applications, an event handler might respond to button clicks, key presses, or other user interactions, triggering the appropriate actions in the program.
Which OOP concept allows classes to act as templates for creating objects?
A Polymorphism
B Abstraction
C Inheritance
D Classes
In OOP, classes serve as blueprints or templates for creating objects. They define the properties and behaviors (methods) that objects instantiated from the class will have, providing structure and consistency to the objects.
What is the purpose of Event-Driven Programming in GUI development?
A Handle multiple threads
B Handle system memory
C Control hardware interaction
D Respond to user inputs
In GUI development, event-driven programming allows the application to respond dynamically to user inputs, such as mouse clicks or keyboard presses. The flow of the program is driven by these events, making the application interactive.
Which of the following is a common practice in Secure Coding?
A Avoid method overloading
B Validate user input
C Limit the use of classes
D Minimize code reusability
Secure coding practices include validating user input to prevent security risks such as buffer overflows, SQL injections, or cross-site scripting (XSS). Proper validation ensures that data entered into the system is safe and expected.
What is Dynamic Method Dispatch important for in OOP?
A Runtime polymorphism
B Memory optimization
C Error handling
D Code efficiency
Dynamic method dispatch enables runtime polymorphism by allowing the method invoked to be determined based on the actual object type rather than the reference type. This makes method calls more flexible and enables polymorphic behavior in OOP.
What is the role of Encapsulation in Secure Coding in OOP?
A Increases method complexity
B Reduces class inheritance
C Protects object data
D Improves runtime performance
Encapsulation protects an object’s data by restricting direct access and providing controlled access through getter and setter methods. This prevents unauthorized modification of the object’s internal state, contributing to secure coding practices.