This code snippet demonstrates method overriding in object-oriented programming.
Explanation:
1. Class MemoryDevice:
It has a method printPhysicalSize that prints "medium".
2. Class SDCard:
It inherits from MemoryDevice.
It overrides the printPhysicalSize method to print "small" instead.
3. Code Execution:
sdCard = SDCard() creates an instance of the SDCard class.
sdCard.printPhysicalSize() calls the printPhysicalSize method of the SDCard class (because it overrides the method in the parent class).
Key Concept:
When a method in a subclass overrides a method in the parent class, the subclass version is executed for objects of the subclass.
Output:
The method in SDCard prints "small". Therefore, the correct answer is: small.
0 Comments:
Post a Comment