クラスメンバの隠蔽
- 基底クラスのメンバを派生先で隠蔽するとコンパイル時に警告になる
- 意図した隠蔽であることを明示するために new キーワードをつけて宣言する
class Base
{
public void Hello () {}
}
class Inherit : Base
{
new public void Hello () {} // new はなくても効果は一緒
static void Main ()
{
Inherit iObj = new Inherit ();
Base bObj = iObj;
iObj.Hello (); // Inheritのメソッドが実行される
bObj.Hello (); // Baseのメソッドが実行される
}
}
トラックバック
- このエントリーにトラックバック:
- http://frog.raindrop.jp/cgi-bin/mt/mt-tb.cgi/2129
コメント