Difference between overwrite and override in programming


In programming, “overwrite” and “override” have distinct meanings:

Overwrite:

  • Literally means to replace existing data or code with new data or code.
  • If you have a file or a block of code and you replace it with something else, you are overwriting it.
  • Example: If you have a backup of a file and you save a new version of the file on top of the old one, you overwrite the old file.

Override:

  • Commonly used in the context of object-oriented programming (OOP) to indicate that a subclass provides a specific implementation of a method that is already provided by one of its superclasses. The subclass’s version of the method “overrides” the superclass’s version.
  • It means to change or extend the default behavior of a method or function.
  • Example: In Java, the @Override annotation is used to indicate that the subsequent method overrides a method from its superclass.

If you updated some code, the term you use depends on the nature of the update:

If you replaced the existing code with a completely new version, then you “overwrote” the old code.

If you made modifications to an existing code base to change or extend some of its behavior, you might say you “modified” or “updated” the code. If your changes are specifically related to object-oriented method behavior in subclasses, then you “overrode” certain methods.

In general conversation or documentation, if you’re talking about replacing code entirely, you’d typically use “overwrite.” If you’re talking about making modifications to existing methods or functions in an OOP context, “override” might be more apt. However, in many contexts, especially outside of OOP, “modify” or “update” would be most commonly used to describe general code changes.


Author: robot learner
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source robot learner !
  TOC