I have the stituation that there is an Interface I with a method m, and two implementation classes A and B that behave differently.
the objects of A and B use only memory for their value and reference types, not for their methods. An object of A stored in a variable of type I is stored with a reference (pointer size overhead) plus the size of the object. Now the method m is called. Now where is this one bit of information stored, that method m from class A has to be called instead from class B?
This question also nags me with C++ virtual methods.
interface I { void m(); }
class A implements I { void m(){println("a");} }
class B implements I { void m(){println("b");} }
In C++, each object typically contains a hidden pointer (the vptr) to a table of function addresses (the vtable). There is one vtable per class, containing the addresses of its virtual function implementations. See http://en.wikipedia.org/wiki/Virtual_method_table.
I imagine Java implements things in a similar manner (although I haven’t looked into this).