面向对象编程 [英] Object Oriented Programming
本文介绍了面向对象编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下课程
I have following class as
public abstract class BaseClass
{
public virtual void VirtualMethod()
{
Console.WriteLine("NewBaseClass:VirtualMethod");
}
}
public class DerivedClass : BaseClass
{
public override void VirtualMethod()
{
Console.WriteLine("NewClassA:VirtualMethod");
}
}
现在我想调用基类方法使用 base 关键字创建DerivedClass的对象
请帮助
Now i want to call base class method by creating object of DerivedClass using base keyword
Please help
推荐答案
在您的示例(C ++)中:
In your example (C++):
// Create an instance of DerivedClass
DerivedClass *dc = new DerivedClass();
// BTW this will work as well:
//BaseClass *dc = new DerivedClass();
// Call the method of base class
dc->BaseClass::VirtualMethod();
// Let' clean
delete dc;
此示例应提供如下输出:
> NewBaseClass:VirtualMethod
This example shall give an output like:
>NewBaseClass:VirtualMethod
看看这里:http://msdn.microsoft.com/en-us/library/hfw7t1ce.aspx [ ^ ]
关于继承的更多信息:
http://msdn.microsoft.com/en-us/library/ms173149.aspx [ ^ ]
http://msdn.microsoft.com/en-us/ library / ms228387%28v = vs.80%29.aspx [ ^ ]
Have a look here: http://msdn.microsoft.com/en-us/library/hfw7t1ce.aspx[^]
More about inheritance:
http://msdn.microsoft.com/en-us/library/ms173149.aspx[^]
http://msdn.microsoft.com/en-us/library/ms228387%28v=vs.80%29.aspx[^]
这篇关于面向对象编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文