1) Assume:
• B1
defines methods virtualM()
and nonvirtualM()
, where former method is virtual while the latter is non-virtual
• B2
derives from B1
• B2
overrides virtualM()
• B2
is defined inside assembly A
• Application app
doesn’t have a reference to assembly A
In the following code application app
dynamically loads an assembly A
, creates an instance of a type B2
and calls methods virtualM()
and nonvirtualM()
:
Assembly asemb=Assembly.Load(“A”);
Type t= asemb.GetType(“B2”);
B1 a = ( B1 ) Activator.CreateInstance ( “t” );
a.virtualM();
a.nonvirtualM();
a) Is call to a.virtualM()
considered early binding or late binding?
b) I assume a call to a.nonvirtualM()
is resolved during compilation time?
2) Does the term late binding refer only to looking up the target method at run time or does it also refer to creating an instance of given type at runtime?
thanx
EDIT:
1)
-- I assume a call to a.nonvirtualM() is resolved during compilation time?
- Yep.
If we have:
A a = new A();
a.M();
As far as I know, it is not known at compile time where on the heap (thus at which memory address ) will instance a
be created during runtime.
Now, with early binding the function calls are replaced with memory addresses during compilation process. But how can compiler replace function call with memory address, if it doesn’t know where on the heap will object a
be created during runtime ( here I’m assuming the address of method a.M
will also be at same memory location as a
)?
2)
The method slot is determined at compile time
I assume that by method slot you’re referring to the entry point in V-table?