Reputation: 238
I know the functions are loaded only once in the memory. My doubt is... if we create an object of a class how it refer the function? What is the thing behind the object creation and function calling? Is there any pointer in the object to the function?
Upvotes: 2
Views: 93
Reputation: 156642
I believe you're looking for the term "virtual method table".
This is the mechanism that languages (compilers) use to determine what method to actually invoke when a call to a virtual function is made (and in Java all functions are virtual).
Upvotes: 1
Reputation: 34421
When you create an object, only it's data fields are being created (allocated). Class methods forever resides in memory during whole program run.
Does object have pointer to the method or no is language-dependent. For example, in C++ object are containing pointers to virtual methods, while normal and static methods are called just by their constant addresses.
Upvotes: 1