forked from solstice/solstice
33 lines
576 B
Plaintext
33 lines
576 B
Plaintext
struct Person {
|
|
protected name = ""
|
|
private age = 0
|
|
|
|
def greet() string {
|
|
return "Hello, " + self.name + "!"
|
|
}
|
|
|
|
def dance() string {
|
|
return "Dancing..."
|
|
}
|
|
|
|
constructor(string name, int age) {
|
|
self.name = name
|
|
self.age = age
|
|
}
|
|
|
|
destructor {
|
|
// We don't need to do anything here.
|
|
}
|
|
|
|
}
|
|
|
|
max = Person("Max", 16)
|
|
|
|
puts max
|
|
puts max.greet()
|
|
puts max.name
|
|
// puts max.age (causes compile time error, age is private)
|
|
// max.name = "Maximilian" (causes compile time error, name is protected)
|
|
|
|
max.dance()
|