forked from solstice/solstice
Constructors
This commit is contained in:
@@ -1,18 +1,16 @@
|
||||
use io
|
||||
struct Person {
|
||||
name = ""
|
||||
age = 0
|
||||
def greet() string {
|
||||
return "Hello, " + self.name + "!"
|
||||
}
|
||||
|
||||
struct dingus {
|
||||
x = 5
|
||||
y = "dingus"
|
||||
constructor(string name, int age) {
|
||||
self.name = name
|
||||
self.age = age
|
||||
}
|
||||
}
|
||||
|
||||
e = new dingus
|
||||
puts e
|
||||
puts dingus
|
||||
|
||||
puts e.x
|
||||
println(e.y)
|
||||
|
||||
e.x = 7
|
||||
e.y = "heheheha"
|
||||
puts e.x
|
||||
println(e.y)
|
||||
max = Person("Max", 16)
|
||||
puts max
|
||||
puts max.greet()
|
||||
Reference in New Issue
Block a user