with C#, java or c++ …
we have the following classes
class A
{
void x(){y();}
void y(){}
}
class B :A
{
void y(){};
void a(){x();}
}
//in main or somewhere
B b=new B();
b.a();
when function “a” is called it will call the base “x” function
the question is, which function the function “x” will call (base y() / derived y() ) ?
and how can we control which one to invoke !!
note: take the concept, i know that the three languages are not the same.
(assuming you meant to declare everything as public, and use appropriate syntax for each language)
In Java and C# it will call B::y.
In C++ it will call A::y.
In C++, If you had of declared A::y as virtual it will call B::y instead.
Implementing static dispatch (A::y) is more performant than dynamic dispatch (B::y), so the option is left open in C++ to choose between them (virtual or non-virtual). For Java and C# the language designers decided to keep it simple and only allow dynamic dispatch, so there is not way in those two languages to do static dispatch (A::y).