私は次のベローを持っています。
コンパイラは、変数がコンストラクターにある場合にのみ、派生クラスの変数 flyBehaviour を認識します。何故ですか?
abstract class Duck
{
protected IFlyBehaviour flyBehaviour;
public IFlyBehaviour FlyBehaviour
{
get
{return flyBehaviour;}
set
{flyBehaviour=value;}
}
}
class MullardDuck: Duck
{
flyBehaviour //the compiler doesn't recognize this variable here
public MullardDuck()
{
flyBehaviour = new FlyWithWings(); //here the compiler recognize this variable
}
}