Override: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Override
| Old | New | Line | |
|---|---|---|---|
| 1 | + | Back to [[Reserved words]]. | |
| 2 | + | ||
| 3 | + | The **override** modifier: | |
| 4 | + | ||
| 5 | + | - is part of object-oriented programming; | |
| 6 | + | - allows a virtual and abstract method from a parent class to be overridden (replaced). | |
| 7 | + | ||
| 8 | + | Example: | |
| 9 | + | ||
| 10 | + | ``` pascal | |
| 11 | + | Type | |
| 12 | + | TParentClass = class // The parent class is derived from the base class | |
| 13 | + | public | |
| 14 | + | function volume : double; virtual; abstract; // This method must be one from this class | |
| 15 | + | // - derived class can be hidden or overridden | |
| 16 | + | function surface double; virtual; abstract; // This method must be one from this class | |
| 17 | + | // - derived class can be hidden or overridden | |
| 18 | + | end; | |
| 19 | + | ||
| 20 | + | Type | |
| 21 | + | TChildClass = class(ParentClass) // The child class is derived from the parent class | |
| 22 | + | public | |
| 23 | + | function volume : double; override; // the virtual method is overridden (replaced) | |
| 24 | + | function surface double; override; // the virtual method is overridden (replaced) | |
| 25 | + | end; | |
| 26 | + | ``` | |
| 27 | + | ||
| 28 | + | --- | |
| 29 | + | *From the Free Pascal wiki, page "Override", as it stood on 2020-02-23 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
