Andrew

Andrew

  • NA
  • 3
  • 0

use subclass field in inherited method

Aug 1 2009 6:36 PM
Hi,
I can't figure out how to get a method of an abstract class to refer to the values of a field stored in the subclasses.
Example in pseudo-code:
class Parent{
field _Description = "I'm the parent";
void PrintDescription(){
Console.WriteLine(this._Description);
)
}

class Child: Parent{
field _Description = "I'm the child";
}

If I instantiate the child class and call its PrintDescription() method, it prints
"I'm the parent"

How can I tell the 'PrintDescription()' method in the base class to always use the subclass's value for the field '_Description'?

Thanks.

Answers (3)