chapter 13
This commit is contained in:
9
examples/inheritance.lox
Normal file
9
examples/inheritance.lox
Normal file
@@ -0,0 +1,9 @@
|
||||
class Doughnut {
|
||||
fn cook() {
|
||||
print("Fry until golden brown.");
|
||||
}
|
||||
}
|
||||
|
||||
class BostonCream < Doughnut {}
|
||||
|
||||
BostonCream().cook();
|
14
examples/super.lox
Normal file
14
examples/super.lox
Normal file
@@ -0,0 +1,14 @@
|
||||
class Doughnut {
|
||||
fn cook() {
|
||||
print("Fry until golden brown.");
|
||||
}
|
||||
}
|
||||
|
||||
class BostonCream < Doughnut {
|
||||
fn cook() {
|
||||
super.cook();
|
||||
print("Pipe full of custard and coat with chocolate.");
|
||||
}
|
||||
}
|
||||
|
||||
BostonCream().cook();
|
Reference in New Issue
Block a user