-
Notifications
You must be signed in to change notification settings - Fork 1
/
1-5-prototype.vala
45 lines (34 loc) · 986 Bytes
/
1-5-prototype.vala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Sheep {
protected string name;
protected string category;
public Sheep (string name, string category = "Mountain Sheep") {
this.name = name;
this.category = category;
}
public void set_name (string name) {
this.name = name;
}
public string get_name () {
return name;
}
public void set_category (string category) {
this.category = category;
}
public string get_category () {
return category;
}
// No Object clone method, lets implement a clone method
public Sheep clone () {
return new Sheep (name, category);
}
}
public static int main (string[] args) {
var original = new Sheep ("Jolly");
print ("%s\n", original.get_name ());
print ("%s\n", original.get_category ());
var cloned = original.clone ();
cloned.set_name ("Dolly");
print ("%s\n", cloned.get_name ());
print ("%s\n", cloned.get_category ());
return 0;
}