In object-oriented programming, what mechanism allows a subclass to provide a specific implementation of a method already defined in its superclass?
Answer and explanation
Correct answer: C. Method overriding
- Step 1: Method overriding occurs when a subclass re-implements a method with the exact same name, return type, and parameters as in the superclass.
- Step 2: It enables dynamic runtime polymorphism (virtual method dispatch).
Answer
Method overriding.
Why not the others: 'Method overloading' defines multiple methods with the same name but different signatures within the same class; 'Data encapsulation' hides private state; 'Multiple instantiation' creates multiple objects.
Practise more Python Programming, Data Structures, Algorithms, Networks and Cybersecurity.
Free questions with an explanation for every one, and full timed Saudi Secondary School Certificate mock tests.
More Python Programming, Data Structures, Algorithms, Networks and Cybersecurity questions
- What is the time complexity of searching for an element in an unsorted array of elements using linear search?
- What is the output of the following Python expression: `[x**2 for x in range(5) if x % 2 == 1]`?
- Which data structure operates on a Last-In, First-Out (LIFO) access principle?
- Which SQL clause is used to filter aggregated group records after a `GROUP BY` statement has been applied?
- What type of network topology connects all nodes to a central forwarding device such as a network switch?
- In cybersecurity, what type of malicious attack overwhelms a web server with massive volumes of traffic from multiple compromised sources to…