can anyone explain how a call to an inherited function is executed in derived class.
say i have a function in Base class

class Base
{
    void func() { ... }
}

and this class is inherited by any other class

class Derived extends Base
{ ... }

now suppose, i'm calling func() with derived class object like this

Derived obj = new Derived();
obj.func();

Now, my question here is that where this func() is, which is getting called.
is the function definition for func() is copied from Base class to Derived class while inheriting and is being called from there or this func() function call is passed directly to Base class.

有帮助吗?

解决方案

Base class version of the function will be called here

其他提示

Since your derived class has not provided an implementation for that function, the function is called using the base class's implementation.

Assuming you need to know what the base class has provided as an implementation, at some point the base class implementation will need to be read by the executing agent.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top