子類賦值給父類
using System;using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class father
{
private int a;
public void showstring()
{
Console.Write("父類中的方法");
}
public int Ap
{
get {return a;}
set { a = value; }
}
}
class son : father
{
public void sonshowstring()
{
Console.Write("子類中的方法");
}
}
class Program
{
static void Main(string[] args)
{
father fa = new father();
fa.showstring();
son so = new son();
father fa1 = so;
fa1.showstring();
}
}
}
father fa1=so是將子類賦值給父類,請問,這裡是什麼意思呢?