DevilKing's blog

冷灯看剑,剑上几分功名?炉香无需计苍生,纵一穿烟逝,万丈云埋,孤阳还照古陵

0%

Jvm Handle Method overloading and overriding

原文链接

We know that overloaded methods are not called polymorphic and get resolved at compile time and this is why sometime method overloading is also known as compile time polymorphism or early/static binding.

1
javap -verbose OverridingInternalExample

programe bytecode

Bytecode for anyMammal.speak() and humanMammal.speak() are the same ( invokevirtual #4 // Method org/programming/mitra/exercises/OverridingInternalExample$Mammal.speak:()V ) because according to compiler both methods are called on Mammal reference.

JVM uses the invokevirtual instruction to invoke Java equivalent of the C++ virtual methods.

The Java virtual machine does not mandate any particular internal structure for objects 4.

根据vstable来算,

There is only one vtable per class means it is unique and same for all objects of a class similar to Class object.

Now instead of creating new entries for these methods with updated references. JVM will modify the references to the already present methods on the same index where they were present earlier and will keep the same method names.