Shashi
Shashi

Reputation: 746

mechanism of calling inherited functions

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.

Upvotes: 0

Views: 43

Answers (2)

user2668821
user2668821

Reputation:

Base class version of the function will be called here

Upvotes: 2

Dragonsdoom
Dragonsdoom

Reputation: 210

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.

Upvotes: 2

Related Questions