In Java:
class Base {
public Base() { System.out.println(\"Base::Base()\"); virt(); }
void virt() { System.out.println(\"Base::virt()\"); }
}
clas
In Java, method invocation is based on object type, which is why it is behaving like that (I don't know much about c++).
Here your object is of type Derived
, so jvm invokes method on Derived
object.
If understand Virtual concept clearly, equivalent in java is abstract, your code right now is not really virtual code in java terms.
Happy to update my answer if something wrong.