diff options
Diffstat (limited to 'vala.html.markdown')
-rwxr-xr-x | vala.html.markdown | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/vala.html.markdown b/vala.html.markdown index 11165aa4..3103f9c5 100755 --- a/vala.html.markdown +++ b/vala.html.markdown @@ -353,6 +353,34 @@ class SubDemo : SuperDemo { } } +// Abstract Classes and Methods + +public abstract class OperatingSystem : GLib.Object { + public void turn_on() { + stdout.printf("Booted successfully.\n"); + } + public abstract void use_computer(); +} + +public class Ubuntu : OperatingSystem { + public override void use_computer() { // Abstract methods must be overridden + stdout.printf("Beep boop\n"); + } +} + +// Add default behavior to an abstract method by making it "virtual". + +public abstract class HardDrive : GLib.Object { + public virtual void die() { + stdout.printf("CLICK-CLICK-CLICK\n"); + } +} +public class MyHD : HardDrive { + public override void die() { + return; + } +} + ``` * More Vala documentation can be found [here](https://valadoc.org/). * Read about building GUIs with GTK+ and Vala [here](http://archive.is/7C7bw). |