BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / java / #49809同步于 2016/4/28
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖

[问题]接口和抽象类

dongqing
2016/4/28镜像同步46 回复
“接口是特殊的抽象类”这句话对吗?
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
olo机器人#1 · 2016/4/28
java不是很了解,但我知道接口不是类,所以这句话不对
yhs950826机器人#2 · 2016/4/28
书上是这么说的啊[ema17]
wht机器人#3 · 2016/4/28
要看你怎么理解了 接口区别于抽象类在于多继承,但是接口的定义类似于抽象类
BUPTbinnsd机器人#4 · 2016/4/28
接口一种特殊的类,这句话也对吧? 发自「贵邮」
Naruto666机器人#5 · 2016/4/28
感觉区别挺大,接口提供了一种JAVA类不能多继承的解决方案,提高了灵活性。还有,更有利于程序的扩展。 通过『我邮2.0』发布
lusuo9机器人#6 · 2016/4/28
别误导学弟学妹们啦~ 这句话是对的。 【 在 olo 的大作中提到: 】 : java不是很了解,但我知道接口不是类,所以这句话不对
Silencecjx机器人#7 · 2016/4/28
这种概念性问题,个人觉得最好是定义入手。 Oracle关于Interface的定义 https://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html 1. “In the Java programming language, an interface is a reference type, similar to a class, that can contain only constants, method signatures, default methods, static methods, and nested types” Oracle关于Abstract Class的定义: https://docs.oracle.com/javase/tutorial/java/IandI/abstract.html 2. “An abstract class is a class that is declared abstract—it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed.” 3.Abstract Classes Compared to Interfaces Abstract classes are similar to interfaces. You cannot instantiate them, and they may contain a mix of methods declared with or without an implementation. However, with abstract classes, you can declare fields that are not static and final, and define public, protected, and private concrete methods. With interfaces, all fields are automatically public, static, and final, and all methods that you declare or define (as default methods) are public. In addition, you can extend only one class, whether or not it is abstract, whereas you can implement any number of interfaces. 从上面的三个内容,首先,Interface不是一种特殊的Abstract Class。 但是你要说“接口是一种特殊的抽象类”,这个对不对,看你怎么定义这个抽象类了,是Java里Abstract Class的翻译,还是指的面向对象里的抽象类。 “抽象类往往用来表征对问题领域进行分析、设计中得出的抽象概念,是对一系列看上去不同,但是本质上相同的具体概念的抽象。” 如果是前者,答案应该是否,也就是前面有同学提到的,“接口区别于抽象类在于多继承,但是接口的定义类似于抽象类” 如果是后者,答案应该是是,个人理解为,面向对象里只要是对具体抽象的类都可以理解为抽象类。
MrBrain机器人#8 · 2016/4/28
严格抠字眼,这句话不对。但这句话的意思对。
royzxq机器人#9 · 2016/4/28
如果从C++来看,我觉得可以这么说吧,因为如果你要实现一个interface差不多就是类里只包含纯虚函数。