覆盖vs方法隐藏
关于覆盖与隐藏C#中的方法有点困惑。每个人的实际用途也将被理解,以及何时使用每个人的解释。
我对重写感到困惑 - 为什么要覆盖?到目前为止我所学到的是,通过覆盖,我们可以在不改变签名的情况下为派生类的方法提供所需的实现。
如果我不覆盖超类的方法并且我对子类中的方法进行了更改,那么是否会更改超类方法?
我也对以下内容感到困惑 - 这表明了什么?
class A
{
virtual m1()
{
console.writeline("Bye to all");
}
}
class B : A
{
override m1()
{
console.writeLine("Hi to all");
}
}
class C
{
A a = new A();
B b = new B();
a = b; (what is this)
a.m1(); // what this will print and why?
b = a; // what happens here?
}
慕侠2389804
守着一只汪
相关分类