我的两个类root 和 branch,是这样的:
-- root ----------------
public class root
{
public root()
{
//
// TODO: Add constructor logic here
//
}
public virtual void tell()
{
System.Windows.Forms.MessageBox.Show("root");
}
}
-- branch -----------
public class branch:root
{
public branch()
{
//
// TODO: Add constructor logic here
//
}
public override void tell()
{
System.Windows.Forms.MessageBox.Show("branch");
}
public void parentTell()
{
base.tell();
}
}--- main ----
branch objBrh = new branch();
objBrh.tell();
objBrh.parentTell(); // output "root"
root r = objBrh;
r.tell(); // output "branch"想请教一下,这个列子里究竟有几份root类的tell()方法呢?
-- root ----------------
public class root
{
public root()
{
//
// TODO: Add constructor logic here
//
}
public virtual void tell()
{
System.Windows.Forms.MessageBox.Show("root");
}
}
-- branch -----------
public class branch:root
{
public branch()
{
//
// TODO: Add constructor logic here
//
}
public override void tell()
{
System.Windows.Forms.MessageBox.Show("branch");
}
public void parentTell()
{
base.tell();
}
}--- main ----
branch objBrh = new branch();
objBrh.tell();
objBrh.parentTell(); // output "root"
root r = objBrh;
r.tell(); // output "branch"想请教一下,这个列子里究竟有几份root类的tell()方法呢?
root r = objBrh;
r.tell(); 用的是 branch.tell();
root r = objBrh;//关键是这里.
r.tell(); // output "branch"我没有疑问,主要是这句
objBrh.parentTell(); // output "root"
这个方法里用了base.tell(),还能访问到root.tell()(output "root"),说明root.tell()还存在,那我override的是哪里的tell()呢?