-
Notifications
You must be signed in to change notification settings - Fork 0
Classes
Sxtanna edited this page Jul 9, 2020
·
3 revisions
class 'name'{(property declarations)}{::['super types']} {
(properties and functions)
}
class
- All classes start with the
class
keyword.
- name
- Class names must follow
UpperCamelCase
naming standards.
- property declarations
- Classes support declaring properties that need to be passed. (sort of like a constructor)
- super types
- Classes can "extend" traits, copying all properties and functions from the trait into this class.
- properties and functions
- Classes can hold any number of properties and functions, this is also where implementations of trait members would be.
trait Being(val name: Txt)
class Human(val age: Int)::[Being] {
fun sayMyName {
push "My name is $name"
}
fun sayMyAge {
push "My age is $age"
}
}
val sxtanna = Human { name: "Sxtanna", age: 21 }
sxtanna.sayMyName() // prints "My name is Sxtanna" to console.
sxtanna.sayMyAge() // prints "My age is 21" to console.