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

查看:33
本文介绍了为什么我们需要 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.

例如:

Abstract 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天全站免登陆