Inherited from v1.0.0

class / extends / super

A class defines a type with methods and fields. extends declares inheritance from a parent class. super chains to the parent (constructor or method). The Bangla forms are শ্রেণী, প্রসারিত, and উপরের.

Defining a class

Methods take self as their first parameter explicitly — there is no implicit this. An init method, if present, runs on construction.

class Counter {
    function init(self, start) {
        self.value = start;
    }
    function increment(self) {
        self.value = self.value + 1;
    }
    function get(self) {
        return self.value;
    }
}

var c = Counter(10);     // no `new` keyword
c.increment();
c.increment();
print(c.get());          // 12

Notes:

  • Construction is ClassName(args) — there is no new keyword.
  • Method calls (c.increment()) automatically pass the instance as self.
  • If a class has no init, zero-arg construction works: Bag().
  • Fields are set via self.field = value and read via self.field (or obj.field from outside).

Inheritance with extends

class Animal {
    function init(self, name) {
        self.name = name;
    }
    function speak(self) {
        return self.name + " makes a sound";
    }
}

class Dog extends Animal {
    function init(self, name, breed) {
        super(name);              // chain parent's init
        self.breed = breed;
    }
    function speak(self) {        // override
        return self.name + " barks";
    }
}

var d = Dog("Rex", "labrador");
print(d.speak());                 // Rex barks

super(...) inside init calls the parent's constructor.

Calling parent methods

Use super.method(args) to delegate to the parent's version of a method:

class Dog extends Animal {
    function describe(self) {
        return super.describe() + " breed=" + self.breed;
    }
}

You can chain through multiple levels — a subclass's super.x() resolves against its direct parent, regardless of how deep the hierarchy goes.

Multi-level inheritance

class Puppy extends Dog {
    function speak(self) {
        return super.speak() + " (puppy yip!)";
    }
}

var p = Puppy("Buddy", "poodle");
print(p.speak());    // Buddy barks (puppy yip!)

What's not here

  • No this. Always use self, declared as the first method parameter.
  • No new. Just call the class: Counter(10).
  • No static methods. If you need a module-level helper, write a top-level function.
  • No access modifiers. No private / protected / public — all fields and methods are accessible.
  • No multiple inheritance. A class extends at most one parent.

Bangla form

শ্রেণী Counter {
    ফাংশন init(self, start) {
        self.value = start;
    }
    ফাংশন increment(self) {
        self.value = self.value + 1;
    }
}

চলক c = Counter(10);
c.increment();
print(c.value);   // 11