Types and OOP Inheritance

Inheritance and Interfaces

Klyn supports class inheritance, interface implementation, abstract members, and explicit calls to the parent implementation through super. These features keep object hierarchies structured without hiding control flow.

Extending a Class
abstract class Shape:
    public property color as String

    public Shape(color as String = "black"):
        this.color = color

    public abstract area() as Double

class Circle extends Shape:
    public property radius as Double

    public Circle(radius as Double = 1):
        super("black")
        this.radius = radius

    public area() as Double:
        return Math.PI * this.radius ** 2
Using super
class Base:
    public doSomething():
        print("base")

class Derived extends Base:
    public doSomething():
        super.doSomething()
        print("derived")
Constructor rule

When you call super(...) explicitly from a constructor, it must be the first effective call in that constructor body.

Overriding

Use override when you want to replace inherited behavior and make that decision obvious in the source code.

public override toString() as String:
    return "Circle"
Abstract Classes and Methods

Abstract classes may define shared state and behavior while still leaving required operations unimplemented for subclasses.

abstract class Shape:
    public abstract area() as Double

Abstract types are not instantiable directly.

Implementing Interfaces
interface Runnable:
    public run() as Void

class Task implements Runnable:
    public run() as Void:
        print("running")

Interfaces describe required behavior. They may also carry static helpers when that improves the API shape.

Type Checks Across a Hierarchy
shape = Circle()
assert shape is Shape
assert shape is Circle
assert shape is not String