为什么我们需要Java中的抽象类? [英] why do we need abstract classes in Java?

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

问题描述

为什么我们需要Java中的抽象类?如果你永远不会把它变成一个对象,为什么会有它的第一位?你如何使用它?为什么会有?我想知道同样的事情与抽象方法。我发现它似乎是一个类似的概念,有一个超类没有任何子类,可能是无关紧要的。

Why do we need abstract classes in Java? If you're never going to make it into an object, why have it in the first place? How do you use it? Why is it there? I'm wondering the same thing with abstract methods. I find it seems like a similar concept to having a super class with NO subclasses that could ever matter to be made.

推荐答案

抽象类可以用作其他类的模板类型。抽象类将为所有扩展它的类保留共同的功能。

An abstract class can be used as a type of template for other classes. The abstract class will hold common functionality for all classes that extend it.

例如:

Abtract Class Animal 

所有动物都会移动,呼吸和繁殖,进入动物类。

All animals move and breathe and reproduce so these can be put into the Animal Class.

现在

 Concrete Class Dog, Cat etc.

已经提供了这些基本功能。

Have these base functions already provided.

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

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