明らかにバーチャルとオーバーライドを使用するのは通常の状況ですが、このテレコムのサンプルカウントはありますか?バーチャルキーワードを使用しない多態
public class Pipe
{
// whole bunch of protected member variables such as bandwidth, latency, download limit
// etc,
public int GetCost()
{
// work out cost based on above
}
}
public class BigFatPipe : Pipe
{
public BigFatPipe()
{
// sets up the member variables one way
}
}
public class CheapestPossiblePipe: Pipe
{
public CheapestPossiblePipe()
{
// sets up the member variables another way
}
}
その後、あなたは次の2つの異なる答えを得るでしょう
PrintPrice(new BigFatPipe())
PrintPrice(new CheapestPossiblePipe())
public void PrintPrice(Pipe pipe)
{
int a = pipe.GetCost();
....
}
を呼ぶかもしれません。これは最も有用な例ではありませんが、数えられますか?
ですか?あなたはあなたの質問に関連するタグだけを使うべきです。 – Nasreddine
多態性は、オブジェクトが多くの形を取る能力です。メソッド自体をオーバーライドする必要はありません。 –
それはクロス言語であり、私はJavaと同様に他の言語を含む可能性があります。多形性は私が大いに注目すると思ったタグではなかった – tony