在其子类的子类中用同名函数重写基类中的函数(多重继承)?
考虑以下内容,仅程序体,语法不正确:
class super
{
func1();//the method which is to be be overridden
}
class sub1 extends super
{
func1();
}
class sub2 extends sub1
{
func1();
}
class Main
{
main()
}
Consider the following, only program body, syntax not correct:
class super
{
func1();//the method which is to be be overridden
}
class sub1 extends super
{
func1();
}
class sub2 extends sub1
{
func1();
}
class Main
{
main()
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
new
或virtual
,具体取决于您的意图)new
orvirtual
, depending on your intentions)多重继承是一个类继承多个类的情况。 Wiki
示例:类 D 派生自类 B1 和类 B2
您的示例,正如 itowlson 已经指出的那样out,是两个级别的单继承,这与多重继承不同。
Multiple Inheritance is the scenario when one class inherits from multiple classes. Wiki
Example: class D derives from both class B1 and class B2
Your example, as itowlson already pointed out, is two levels of single inheritance, which is not same multiple inheritance.