S
S
syxme2021-09-30 10:39:19
OOP
syxme, 2021-09-30 10:39:19

Kotlin inheritance, is it possible to modify the original class?

Is it possible to do something similar in Kotlin?

// original
class ModMe
{
  void Say()
  {
    Print("Hello original");
  }
};

// First mod
modded class ModMe  // this class automatically inherits from original class ModMe
{
  override void Say()
  {
    Print("Hello modded One");
    super.Say();
  }
};

// Second mod
modded class ModMe  // this class automatically inherits from first mod's ModMe
{
  override void Say()
  {
    Print("Hello modded Two");
    super.Say();
  }
};

void Test()
{
  ModMe a = new ModMe(); // modded class ModMe is instanced
  a.Say(); // prints 'Hello modded Two' , 'Hello modded One' and 'Hello original'
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Araya, 2021-09-30
@Araya

Well, try this code in the sandbox.
On topic, no, you can't.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question