virtual methods

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

How would I modifiy the pseudo code below so that if you created an instance
of B, and called the Bar() method of B that is inherited from A, that B's
method F would be called by method Bar instead of A's version of F?? Thanks
in advance.

Mark
*************************************************

class A
{
public void Bar()
{
F();
}
public virtual void F() {}
}

class B: A
{
public virtual void F() {}
}
 
Mark said:
How would I modifiy the pseudo code below so that if you created an instance
of B, and called the Bar() method of B that is inherited from A, that B's
method F would be called by method Bar instead of A's version of F?? Thanks
in advance.

You'd change the declaration in B to:

public override void F()
{
}
 
Back
Top