两者区别
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();
}
}
}
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();
father fa1=new son();
fa1.showstring()
}
}
}
请问这两个加粗部份实例化对象时,效果有区别嘛??是否所达到的目的是一样呢?