Java接口是抽象类吗? [英] Is a Java interface an abstract class?

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

问题描述

我正在完成一些功课,并且在之前的试卷上有一个问题,要求在给定的UML图中命名所有抽象类。我想,相当简单。有一个抽象类和三个接口。这些接口通常是否有资格作为抽象类?

I'm working through some homework and a question on a previous exam paper asks to name all of the abstract classes in a given UML diagram. Fairly straightforward, I suppose. There is one abstract class and three interfaces. Do these interfaces qualify as abstract classes, in general?

推荐答案

事实上,虽然技术上接口可能表示为类似于语言的类Java,我不会认为它们是类。

Thing is, while technically interfaces may be represented as classes in languages like Java, I wouldn't consider them classes.

摘要?当然好。类?否。

Abstract? Hell yes. Class? No.

接口不能有构造函数,也不能有属性,字段,函数体等。接口不能被继承,它们是被实现的(再次,从技术上讲,实现它可能是真的接口实际上是以特定的语言继承它,但这不是我的观点。)接口更像是契约,因为它们没有像类那样定义任何行为。

Interfaces cannot have constructors, neither properties, fields, function bodies, etc. Interfaces cannot be inherited, they are implemented (again, technically it might be true that implementing an interface is actually inheriting it in specific languages, but that's not my point.) Interfaces are more like 'contracts' as they do not define any behaviour whatsoever like classes.

现在,如果这是一个家庭作业,那么你不应该和老师真正争论这些东西。只需查看您的讲义,看看您老师对界面的定义中是否提到课程一词。

Now if this is a homework then you shouldn't really argue about these sort of stuff with the teacher. Just check your lecture notes and see if the word "class" is mentioned anywhere in the your teacher's definition of interface.

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

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