Virtual: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Virtual
| Old | New | Line | |
|---|---|---|---|
| 1 | + | Back to [[Reserved words]]. | |
| 2 | + | ||
| 3 | + | The modifier **virtual**: | |
| 4 | + | ||
| 5 | + | - belongs to object-oriented programming; | |
| 6 | + | - describes a virtual method. | |
| 7 | + | ||
| 8 | + | A virtual method must also be implemented (programmed) in the class in which it was declared. | |
| 9 | + | ||
| 10 | + | A virtual method can be overwritten in a derived class with the reserved word override. | |
| 11 | + | ||
| 12 | + | If a virtual method is to be hidden, the class must be covered with the reserved word [[Reintroduce]]. | |
| 13 | + | ||
| 14 | + | Example: | |
| 15 | + | ||
| 16 | + | ``` pascal | |
| 17 | + | Type | |
| 18 | + | TBody = class | |
| 19 | + | private | |
| 20 | + | dblHeight : double; | |
| 21 | + | public | |
| 22 | + | function volume : double; virtual; // This method can be in one of this class | |
| 23 | + | // derived class can be hidden or overwritten | |
| 24 | + | function surfaceArea double; virtual; // This method must be in one of this class | |
| 25 | + | // derived class can be hidden or overwritten | |
| 26 | + | end; | |
| 27 | + | ``` | |
| 28 | + | ||
| 29 | + | --- | |
| 30 | + | *From the Free Pascal wiki, page "Virtual", as it stood on 2020-03-03 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).* |
