-
Late Binding
Forgive me if I confuse you with this question.
Please ask for more details, and I will try to explain better.
I have a program in C# that is using an interface, base class, and derived class.
The base class is built using an interface contract.
The derived classes are of a similar type, all derived by the same base class, in turn using that same interface contract.
I want to do something similar to the following.
I understand that this code will not compile.
I just slapped this together really quick to get my point across.
What will happen when the base variable is printed to the screen?
Does the base object get erased and repopulated with the second binding?
Code:
//base class
int FooBar = 0;
public Foo(int bar)
{
if (bar == 5)
FooBar == bar;
}
Code:
//dirived class 1
int FooBar = 0;
public Bla1()
{
base.constructor(5)
}
Code:
//dirived class 2
int FooBar = 0;
public Bla2()
{
base.constructor(6)
}
Code:
Foo BlaBase;
BlaBase = new Bla1();
cout<<BlaBase.FooBar;
BlaBase = new Bla2();
cout<<BlaBase.FooBar;
-
does late binding reinitialize the variables of the base class with default values before it repopulates with the new bound class?
-
The FooBar variable in the derived classes is a new variable, it has nothing in common with the one in the base class. You set one variable, and print another.
The variables in the derived classes are useless in your example.
If you still need to access that variable, consider using a protected property.
Oh, and this has nothing to do with late binding. C# has no late binding (yet).