Which of the below given statement(s) is/are correct about Overriding and Overloading?
Qualcomm technical mcq question, verified with a worked answer. Free to practise - no sign-up.
Which of the below given statement(s) is/are correct about Overriding and Overloading?
I) Overriding can be used when we want to change the functionality of some method based on a class.
II) Overloading is useful to add flexibility to a method.
Show answer & explanation
Both statements are correct. Statement I accurately describes method overriding: it allows a subclass to provide a specific implementation of a parent class method, thereby changing functionality based on the class hierarchy. Statement II is also correct: method overloading allows multiple methods with the same name but different signatures (parameters), which adds flexibility by enabling callers to use the same method name with different argument types or counts.
Step-by-step Derivation:
Analyze each statement independently:
Statement I - Overriding: Overriding is an OOP concept where a derived/child class provides its own implementation of a method already defined in the parent/base class. This changes the method's functionality based on the specific class using it. This statement is TRUE.
Statement II - Overloading: Overloading allows multiple methods to share the same name but have different parameter lists (different types, counts, or order of parameters). This provides flexibility because callers can invoke the method with different argument combinations. This statement is TRUE.
Since both statements I and II are correct, the answer is D (Both (I) and (II)).