Copy Code code as follows:
public class Father
{
public void Write () {
Console.WriteLine ("Father");
}
}
public class Mother
{
public virtual void Write ()
{
Console.WriteLine ("Mother");
}
}
public class Boy:father
{
Public new void Write ()
{
Console.WriteLine ("Zi");
}
}
public class Girl:mother
{
public override void Write ()
{
Console.WriteLine ("Female");
}
}
Copy Code code as follows:
static void Main (string[] args)
{
Father Father = new Boy ();
Father. Write ();
Boy Boy = new Boy ();
Boy. Write ();
Mother Mother = new Mother ();
Mother. Write ();
Girl Girl = new Girl ();
Girl. Write ();
Console.ReadLine ();
}
Output:
Father
Child
Mother
Woman
To add the Invoke parent method:
Copy Code code as follows:
public class Boy:father
{
Public new void Write ()
{
Base. Write ();
Console.WriteLine ("Zi");
}
}
public class Girl:mother
{
public override void Write ()
{
Base. Write ();
Console.WriteLine ("Female");
}
}
Output:
Father
Father
Child
Mother
Mother
Woman
Visible, the new and override are the same on the results of the program running.