Skip to main content

Class

import math
class Circle {    init(x: Number, y: Number, radius: Number) {        self.x = x        self.y = y        self.radius = radius    }
    area(): Number { return math.PI * self.radius ^ 2 }    diameter(): Number { return 2 * self.radius }    circumference(): Number { return 2 * math.PI * self.radius }}
const circle = Circle(50, 50, 20)
print("Area: " + circle.area())print("Diameter: " + circle.diameter())print("Circumference: " + circle.circumference())

In this example, a circle class is being declared with an x, y and radius. It has 3 methods, area, diameter and circumference. A constant variable which is set to a new instance of the class is than created. Then the methods are called on the instance.