为什么抽象方法只能在抽象类中声明? [英] Why can abstract methods only be declared in abstract classes?

查看:642
本文介绍了为什么抽象方法只能在抽象类中声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解在抽象类中,方法既可以是抽象的,也可以不是抽象的。但为什么我不能在普通非抽象类中创建抽象方法?

I understand that in abstract classes methods be both abstract, or not. But why can I not create an abstract method in a "normal", non-abstract class?

提前感谢您的任何解释!

Thanks in advance for any explanation!

推荐答案

抽象方法基本上说,没有方法的实现,需要在子类中实现的。但是,如果在非抽象类中有抽象方法,则可以实例化该类并获取一个对象,该对象将具有未实现的方法,您将无法使用该方法打电话。

Abstract method basically says, that there is no implementation of the method and it needs to be implemented in a subclass. However if you had an abstract method in a non-abstract class, you could instantiate the class and get an object, that would have an unimplemented method, which you would be unable to call.

这篇关于为什么抽象方法只能在抽象类中声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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