hello,
I know that in C++ every time I have a "virtual" method or I derive from a class with virtual method, compiler creates a Vtable for each class:
class Instrument {
virtual play() { ................}
};
class Guitar: public Instrument {
play() { playNote(); } //1
};
Instrument* i = new Guitar();
i-> play(); //call 1
class Instrument {
virtual play() { ................}
};
class Guitar: public Instrument {
play() { playNote(); } //1
};
Instrument* i = new Guitar();
i-> play(); //call 1
To copy to clipboard, switch view to plain text mode
Here compiler builds two Vtable, for Instrument and for Guitar (it doens't clear why a vtable for Instrument)....)
However, what does java do? I mean, I know all methods are "virtual" in java by default; then every class has it's vtable by default? Or the vtable is created only at the moment compiler/interpreter see something like "
Instrument* i = new Guitar();"
thanks,
Bookmarks