spool-lang / Spool-Legacy-Repo

Legacy repo for the Spool programming language.
3 stars 0 forks source link

Classes #8

Open RedstoneParadox opened 5 years ago

RedstoneParadox commented 5 years ago

Overview

Classes in Silicon are equivalent to classes in other languages such as Java, Kotlin, and C# in that they are object definitions which can contain functions and variables. They are declared with the class keyword, followed by the name and curly brackets to contain all of the class's variables and functions:


class Foo {

    var x : Int;

    func doFooThing() {

    }

}

Constructors

Class constructors in Silicon are special functions which return a new instance of the class. They are declared with the constructor keyword and written like so:


class Bar {

    var x : Int;

    constructor(x : Int) {
        self.x = x
    }

Inheritance

Virtual Methods and Fields