private and protected fields

This commit is contained in:
2026-04-12 21:16:59 +10:00
parent d24462f844
commit f384e19c06
9 changed files with 133 additions and 8 deletions

View File

@@ -1,10 +1,15 @@
struct Person {
name = ""
age = 0
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
@@ -20,3 +25,8 @@ 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()