summaryrefslogtreecommitdiffhomepage
path: root/vala.html.markdown
diff options
context:
space:
mode:
authorMilo Gilad <milogaccnts@gmail.com>2017-08-25 13:14:24 -0400
committerMilo Gilad <milogaccnts@gmail.com>2017-08-25 13:14:24 -0400
commitbf7ed153ee023ea2ba529ccf4ee486b1a59a183a (patch)
treee3442a61da0eca9ddb272bf18cd68ee4ca7bce4e /vala.html.markdown
parentf560802e77202d249c024678308ee422480df0cb (diff)
Added inheritance
Diffstat (limited to 'vala.html.markdown')
-rwxr-xr-xvala.html.markdown23
1 files changed, 21 insertions, 2 deletions
diff --git a/vala.html.markdown b/vala.html.markdown
index b87e16e6..11165aa4 100755
--- a/vala.html.markdown
+++ b/vala.html.markdown
@@ -244,8 +244,8 @@ class Message : GLib.Object { // Class Message extends GLib's Object
protected bool is_digital = true; // protected (this class and subclasses)
internal bool sent = false; // internal (classes in same package)
- public void send(string message_sender) { // public method
- sender = message_sender;
+ public void send(string sender) { // public method
+ this.sender = sender;
sent = true;
}
@@ -334,6 +334,25 @@ class Animal : GLib.Object {
}
}
+// Inheritance: Vala classes may inherit 1 class. Inheritance is not implicit.
+
+class SuperDemo : GLib.Object {
+ public int data1;
+ protected int data2;
+ internal int data3;
+ private int data4;
+
+ public static void test_method { } // Statics can be called w/out an object
+}
+class SubDemo : SuperDemo {
+ public static void main(string args[]) {
+ stdout.printf((string) data1); // Will compile
+ stdout.printf((string) data2); // Protected can be accessed by subclasses
+ stdout.printf((string) data3); // Internal is accessible to package
+ stdout.printf((string) data4); // Won't compile
+ }
+}
+
```
* More Vala documentation can be found [here](https://valadoc.org/).
* Read about building GUIs with GTK+ and Vala [here](http://archive.is/7C7bw).