定义一个没有任何抽象方法的抽象类 [英] Defining an abstract class without any abstract methods

查看:22
本文介绍了定义一个没有任何抽象方法的抽象类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以定义一个抽象类而不添加抽象方法吗?

Can I define an abstract class without adding an abstract method?

推荐答案

当然.

声明一个抽象类仅仅意味着你不允许它自己被实例化.

Declaring a class abstract only means that you don't allow it to be instantiated on its own.

声明方法抽象意味着子类必须为该方法提供实现.

Declaring a method abstract means that subclasses have to provide an implementation for that method.

这两个是不同的概念,但显然你不能在非抽象类中拥有抽象方法.你甚至可以拥有带有 final 方法的抽象类,但不能反过来.

The two are separate concepts, though obviously you can't have an abstract method in a non-abstract class. You can even have abstract classes with final methods but never the other way around.

这篇关于定义一个没有任何抽象方法的抽象类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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