implementing methods and initializers (ch28)

This commit is contained in:
2024-08-31 10:24:48 +02:00
parent c8cd24afbf
commit 3c1c37799c
9 changed files with 123 additions and 2 deletions

View File

@ -0,0 +1,9 @@
class Scone {
topping(first, second) {
return "scone with " + first + " and " + second;
}
}
var scone = Scone();
var result = scone.topping("berries", "cream");
print result;

View File

@ -0,0 +1,8 @@
class Brunch {
bacon() {}
eggs() {}
}
var brunch = Brunch();
print brunch;
brunch.bacon();

11
samples/ch28_say_name.lox Normal file
View File

@ -0,0 +1,11 @@
class Person {
sayName() {
print this.name;
}
}
var jane = Person();
jane.name = "Jane";
var method = jane.sayName;
method();