mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Added inheritance
This commit is contained in:
parent
f560802e77
commit
bf7ed153ee
@ -244,8 +244,8 @@ class Message : GLib.Object { // Class Message extends GLib's Object
|
|||||||
protected bool is_digital = true; // protected (this class and subclasses)
|
protected bool is_digital = true; // protected (this class and subclasses)
|
||||||
internal bool sent = false; // internal (classes in same package)
|
internal bool sent = false; // internal (classes in same package)
|
||||||
|
|
||||||
public void send(string message_sender) { // public method
|
public void send(string sender) { // public method
|
||||||
sender = message_sender;
|
this.sender = sender;
|
||||||
sent = true;
|
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/).
|
* More Vala documentation can be found [here](https://valadoc.org/).
|
||||||
* Read about building GUIs with GTK+ and Vala [here](http://archive.is/7C7bw).
|
* Read about building GUIs with GTK+ and Vala [here](http://archive.is/7C7bw).
|
||||||
|
Loading…
Reference in New Issue
Block a user