implementing methods and initializers (ch28)
This commit is contained in:
9
samples/ch28_calling_methods.lox
Normal file
9
samples/ch28_calling_methods.lox
Normal 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;
|
8
samples/ch28_methods_initializers.lox
Normal file
8
samples/ch28_methods_initializers.lox
Normal file
@ -0,0 +1,8 @@
|
||||
class Brunch {
|
||||
bacon() {}
|
||||
eggs() {}
|
||||
}
|
||||
|
||||
var brunch = Brunch();
|
||||
print brunch;
|
||||
brunch.bacon();
|
11
samples/ch28_say_name.lox
Normal file
11
samples/ch28_say_name.lox
Normal file
@ -0,0 +1,11 @@
|
||||
class Person {
|
||||
sayName() {
|
||||
print this.name;
|
||||
}
|
||||
}
|
||||
|
||||
var jane = Person();
|
||||
jane.name = "Jane";
|
||||
|
||||
var method = jane.sayName;
|
||||
method();
|
Reference in New Issue
Block a user