什么是抽象类和抽象方法? [英] What are abstract classes and abstract methods?

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

问题描述


可能重复:

Java中的抽象类

我有几个解释,但到目前为止我我无法理解Java中的抽象类和方法是什么。

I got several explanations but so far I'm not able to understand that what are the abstract classes and methods in Java.

有人说它必须对程序的安全性做些什么,其他人说它不是不管怎么说。

Some said it has to do something with the security of the program, other said it isn't anything like that.

即使是来自Dietel&迪特尔的书我不明白它的目的。
我们何时,何地以及为何使用它?

Even from the Dietel & Dietel's book I don't get it's purpose. When,where and why do we use it?

请教你初学者,我真的很感谢你的帮助。

Kindly explain it like you're teaching a beginner, I would really appreciate your help.

推荐答案

抽象类是无法实例化的类。它的唯一目的是扩展其他类。

An abstract class is a class that can't be instantiated. It's only purpose is for other classes to extend.

抽象方法是抽象类中的方法(必须声明为abstract),这意味着扩展的具体类必须将它们覆盖为它们没有正文。

Abstract methods are methods in the abstract class (have to be declared abstract) which means the extending concrete class must override them as they have no body.

抽象类的主要目的是在子类中使用公共代码,但抽象类不应该有自己的实例。

The main purpose of an abstract class is if you have common code to use in sub classes but the abstract class should not have instances of its own.

您可以在此处阅读更多相关信息:抽象方法和类

You can read more about it here: Abstract Methods and Classes

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

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