I learned a lot about how C++ manages its virtual tables in the presence of inheritance (multiple, virtual etc.) and how it lays the objects in memory.
Now, Java only has to worry about single line of inheritance, no instance method hiding etc. so virtual tables should be a bit simpler in this case. I know that Class
files act as "gateways" to method area, where type definitions are stored, including method bytecode I presume. The following two questions come to my mind:
- Is there any vtable/method table structure in Java in general? How is it stored and linked to
Class
objects? - How is inheritance/dynamic method call solved? What I mean is:
Having the following classes and instantiations:
class A{ int f(){...} }
class B extends A{ int f(){...} }
A a = new B();
a.f();
f() in B is called. Is A resolving through Class
file of B the right method pointer?
Thanks a lot in advance for your comments.