When a class inherits from another class, it is implicitly given all the functions of its parent class. For example, if we have a class foo which has functions f1 and f2, and we write another class zed which inherits from class foo, we can call the function zed.f1 or zed.f2, without having to write them again. Effectively, the code for f1 and f2 are copied from foo into bar.
Overriding is when you want zed.f1 to do something other than what foo.f1 does. By re-writing f1 in zed, we change what it does in zed without changing what it does in foo.
This becomes important when we start talking about abstraction. In well-designed object-oriented languages, we can use child classes in place of their parents. For example, if we have yet another class bar that performs operations on a foo, we could give it a zed instead and it would still work, because zed must have all the functions that foo does.
Copyright © 2026 eLLeNow.com All Rights Reserved.