What is difference between method hiding and without "new" keyword?

56 views Asked by At

This is the method hiding:

class SuperClass : GLib.Object {
    public void method1() {
        stdout.printf("SuperClass.method1()\n");
    }
}

class SubClass : SuperClass {
    public new void method1() {
        base.method1();
        stdout.printf("SubClass.method1()\n");
    }
}

And same code without "new" keyword:

class SuperClass : GLib.Object {
    public void method1() {
        stdout.printf("SuperClass.method1()\n");
    }
}

class SubClass : SuperClass {
    public void method1() {
        base.method1();
        stdout.printf("SubClass.method1()\n");
    }
}

What is the difference between these?

edit: in the generated C code absolutely there is no difference, so I think the compiled binary is same.

1

There are 1 answers

0
avojak On BEST ANSWER

There isn't any functional difference, however being explicit with the new keyword is ideal and avoids the compiler warning.