Search code examples
javaoverridingdynamic-binding

Overridden methods and dynamic binding


Is there a possibility for an overridden method to be resolved statically?

And what is the relation between Invoke virtual and dynamic binding? Are all invoke virtual methods dynamically bound?

class Dynamic
{
    public void display()
    {
        System.out.println("in dynamic");
    }
    public static void invoke(Dynamic x)
    {
        x.display();
    }
}

here x.display shows invoke virtual? what does it mean?does it mean it is dynamically bound?


Solution

  • No. Overriden methods cannot be resolved at compile time. They are resolved during Runtime based on type of object.

    InvokeVirtual is the Byte-code way of telling you that a method has been called.