Pergunta

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.

Foi útil?

Solução

Base class version of the function will be called here

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top