抽象方法的目的是什么? [英] What is the purpose of an abstract method?

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

问题描述

abstract public class car 
{   
    abstract void drive();
}

与上面的代码片段一样,抽象方法的目的究竟是什么在Java?根据我的定义,根据定义,他们不允许有身体。

As in the code snippet above, what exactly is the purpose of an abstract method in Java? From what I can gather, by definition, they aren't allowed to have bodies.

推荐答案

当你实现同样的东西时你说的是抽象类,这些东西在很高的层次上是相似的,但它们在如何做事情的细节上有所不同。一个抽象的方法是你怎么说,这里有一些东西,所有扩展这个类的东西必须做,但他们每个人都要指定他们将如何做到这一点。

When you make things implement the same abstract class, you are saying, these things are alike at a high level, but they vary in the particulars of how they do things. An abstract method is how you say, "Here's something that all the things that extend this class have to do, but they each get to specify how exactly they will do it."

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

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