Why private methods cant be virtual?

Daniel Kozak kozzi11 at gmail.com
Tue Sep 22 10:23:08 UTC 2020


On Tue, Sep 22, 2020 at 11:06 AM claptrap via Digitalmars-d-learn <
digitalmars-d-learn at puremagic.com> wrote:

>
> "Functions marked as final may not be overridden in a derived
> class, unless they are also private"
>
> So final private functions can be overriden? It seems not, but
> the sentence is definitely confusing if not just plain wrong.
>
> Yes they can, if you have class A in one module and class B in another
module this will work:

//a.d
class A
{
private final void overrideFun()
{
import std.stdio : writeln;
writeln("A::overrideFun");
}
}

//b.d
import a;
class B : A
{
void overrideFun()
{
import std.stdio : writeln;
writeln("B::overrideFun");
}
}

// main.d
import b;

void main(string[] args)
{
B b = new B;
b.overrideFun;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20200922/bdc5e2b6/attachment.htm>


More information about the Digitalmars-d-learn mailing list