Skip to main content

Subclass

class Rectangle {    init(width: Number, height: Number) {        self.width = width        self.height = height    }
    area(): Number { return self.width * self.height }}
class Square extends Rectangle { # Creating a subclass of Rectangle    init(length: Number) {        super.init(length, length) # Calling the Rectangle init because that is the super    }}
var square = Square(30)print(square.area()) # The class inherits the method from its superclass

Here there's a rectangle class, and a square subclass of the rectangle class.