Skip to content

Inheritance Overview

nova ✩ edited this page Oct 5, 2026 · 4 revisions

Inheritance is common in object oriented programming languages and ClassySK's inheritance is very similar to that of java and c#. Inheritance is a form of object level abstraction that allows you to override certain behaviors of a given object. This is most useful in large, open-ended apis where you want to easily add new features without changing 11 different files to account for the new thing.

Overview with examples

Here is an example using method overriding.

class ZombieEnemy:

	public spawn(loc: location) :: entity:
		spawn zombie at {_loc}
		return last spawned zombie

	public getDamage(victim: entity) :: number:
		return (random integer between 2 and 4)

class BuffZombie extends ZombieEnemy:

	public override spawn(loc: location) :: entity:
		set {_zombie} to super::spawn({_loc})
		set max health of {_zombie} to 40
		return {_zombie}

	public override getDamage(victim: entity) :: number:
		return (random integer between 6 and 8)

Now when we wanna do something with either object, we dont need to care about specifics. Just accept a ZombieEnemy and treat it as such. Nothing in the function itself needs to change to account for the new BuffZombie variant.

function spawnZombie(zombie: ZombieEnemy instance):
    set {_location} to pickLocation({@world})
    {_zombie}::spawn({_location})
    add {_zombie} to {-trackedEnemies::*}

Imagine this in the context of a large server, with dozens of different enemy types in a mob battle gamemode. You can have one Enemy class that every enemy extends, then all the different behaviors of the enemy can be implemented cleanly on the class, rather than with messy if-else trees all over your code.

Language specific details

In ClassySK, all non-static fields/methods are inherited when extending a class, if you want to override a method you must mark it with override. If you try to mask a field by declaring one with the same name on a subclass, you'll get an error. Anything labeled static is also not inherited.

Clone this wiki locally