mirror of
https://github.com/godotengine/godot-website.git
synced 2025-12-31 09:48:43 +03:00
Huge thanks to JohnVeness, AThousandShips, and Meorge for their great help rewording my broken English.
1.9 KiB
1.9 KiB
type, section, subsection, rank, importance, anchor, title, blockquote, text, contributors, read_more, image_alt, image_src, image_src_2x, media_position, position
| type | section | subsection | rank | importance | anchor | title | blockquote | text | contributors | read_more | image_alt | image_src | image_src_2x | media_position | position | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| entry | scripting | gdscript | 1 | 3 | abstract-classes-and-methods | Abstract classes and methods | U Can’t Touch This | You can now declare GDScript classes to be abstract. Declaring a class abstract means that the class is not meant to be instantiated directly. That means that you can prevent instances of a class, let’s say, ``@[Animal](usertype)``, that doesn’t have any purpose on its own other than to be extended by "concrete" classes like ``@[Cat](usertype)`` and ``@[Dog](usertype)``. Abstract classes can also have abstract methods. This means that the method must be implemented in any class that extends it. <figure class="file"> <figcaption>animal.gd</figcaption> ```manual @[@abstract](gdscript-annotation) @[class_name](keyword) Animal @[extends](keyword) @[Node](enginetype) @[@abstract](gdscript-annotation) @[func](keyword) @[cry](function)@[() ->](symbol) @[void](basetype) ``` </figure> <figure class="file"> <figcaption>cat.gd</figcaption> ```manual @[class_name](keyword) Cat @[extends](keyword) @[Animal](usertype) @[func](keyword) @[cry](function)@[() ->](symbol) @[void](basetype) @[# Must be implemented, otherwise an error will be thrown.](comment) @[print](function)@[(](symbol)@["Meow!"](string)@[)](symbol) ``` </figure> |
|
https://github.com/godotengine/godot/pulls?q=is%3Apr+is%3Amerged+67777+106409+107717 | Image of the Add Node window displaying the dimmed out abstract Animal node, and its two extending classes Cat and Dog. | /storage/releases/4.5/images/gdscript-abstract.webp | /storage/releases/4.5/images/gdscript-abstract-2x.webp | top | center-left |