abstract class Animal
{
public string DefaultMessage { get; set; }
public Animal()
{
Console.WriteLine("Animal Cstor called");
DefaultMessage = "Default Speak";
}
public virtual void Speak()
{
Console.WriteLine(DefaultMessage);
}
}
class Dog : Animal
{
public Dog()
: base()//base() redundant. There's an implicit call to base here.
{
Console.WriteLine("Dog cstror called");
}
public override void Speak()
{
Console.WriteLine("Custom Speak");//append new behavior
base.Speak();//Re-use base behavior too
}
}
否則抽象類構造函數和普通類構造函數的區別?
class Animal
{
public string DefaultMessage { get; set; }
public Animal()
{
Console.WriteLine("Animal Cstor called");
DefaultMessage = "Default Speak";
}
public virtual void Speak()
{
Console.WriteLine(DefaultMessage);
}
}
class Dog : Animal
{
public Dog()
: base()//base() redundant. There's an implicit call to base here.
{
Console.WriteLine("Dog cstror called");
}
public override void Speak()
{
Console.WriteLine("Custom Speak");//append new behavior
base.Speak();//Re-use base behavior too
}
}
- 什麼是抽象類的構造函數和普通類的構造函數之間的區別是什麼?
做你自己的家庭作業和讓別人爲你做這件事有什麼區別?你甚至明白你在問什麼? – CodeCaster
## CodeCaster DUDE ##我從CHILDHOOD開始做主題現在我正在尋求這個問題抽象類構造函數和普通類構造函數有什麼區別? –
是的,我可以讀。區別在於一個是抽象的,另一個不是。你爲什麼想知道?那實際上是你想知道的嗎?你將如何處理答案?如果這歸結爲_「解釋C#中的抽象手段」_,它實際上太寬泛了。 – CodeCaster