Files
highground-fork/tests/struct.sols

33 lines
576 B
Plaintext
Raw Normal View History

2026-04-11 17:05:20 +10:00
struct Person {
2026-04-12 21:16:59 +10:00
protected name = ""
private age = 0
2026-04-11 17:05:20 +10:00
def greet() string {
return "Hello, " + self.name + "!"
}
2026-04-12 21:16:59 +10:00
def dance() string {
return "Dancing..."
}
2026-04-11 17:05:20 +10:00
constructor(string name, int age) {
self.name = name
self.age = age
}
2026-04-11 20:42:14 +10:00
destructor {
// We don't need to do anything here.
}
2026-01-25 17:40:07 +11:00
}
2026-04-11 17:05:20 +10:00
max = Person("Max", 16)
2026-04-11 20:42:14 +10:00
2026-04-11 17:05:20 +10:00
puts max
2026-04-11 20:42:14 +10:00
puts max.greet()
2026-04-12 21:16:59 +10:00
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()