如何在不继承类的情况下调用抽象类中的方法? [英] How do you invoke a method in a abstract class without inheriting the class?

查看:473
本文介绍了如何在不继承类的情况下调用抽象类中的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不继承类的情况下调用抽象类中的方法?

How do you invoke a method in a abstract class without inheriting the class?

推荐答案

不,你不能!!

C#中的抽象类和方法 [ ^ ]
No, you can't!!
Abstract classes and methods in C#[^]


我们只能调用抽象类的静态方法而不对其进行子类化。
We can only invoke static methods of an abstract class without sub classing it.


你可以通过为你的方法使用static modifier来调用它。



ex:

摘要A

{

public void G()

{

//代码

}



}



然后你可以这样称呼:

AG();
You can invoke it by using static modifier for your method

ex:
abstract A
{
public void G()
{
// code
}

}

then you can call it like so :
A.G();


这篇关于如何在不继承类的情况下调用抽象类中的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆