interface and abstract 定义的类有什么区别,并举例,谢谢

dhzsir 2004-01-06 04:11:26
interface and abstract 定义的类有什么区别,并举例,谢谢
...全文
52 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
richardemon 2004-01-06
  • 打赏
  • 举报
回复
java没有多重继承,interface可以帮助实现这个功能。

另外 Abstract class: 1.不会产生物件
2.Specification与implementation分离
3.隐藏实作细节,显示操作规格介面
4.在特定的Level隐藏不必要的细节,显示重要的资讯
5.包含 attribute、abstract method、一般method

Interface : 1.不会产生物件
2.提供共同、统一的存取介面
3.降低模组间耦合性
4.包含 interface attribute(not instance attribute)、
abstract method
Hodex 2004-01-06
  • 打赏
  • 举报
回复
鸠摩志没学会72项绝技就是这个道理

只是个比方,没有别的意思,不要误会
zez 2004-01-06
  • 打赏
  • 举报
回复
到用的时候你自然就会明白...
既然存在就有存在的道理.你不明白只是你功力不够,
很多东西是实践中慢慢积累的...
呵呵...
web_spider 2004-01-06
  • 打赏
  • 举报
回复
interface 和abastract有一样的地方就是都含有字母actr
jeffaple 2004-01-06
  • 打赏
  • 举报
回复
有区别吧,找本书看看
gladiatorcn 2004-01-06
  • 打赏
  • 举报
回复
Thinking in Java:

Abstract base classes and interfaces
Often in a design, you want the base class to present only an interface for its derived classes. That is, you don’t want anyone to actually create an object of the base class, only to upcast to it so that its interface can be used. This is accomplished by making that class abstract by using the abstract keyword. If anyone tries to make an object of an abstract class, the compiler prevents it. This is a tool to enforce a particular design.
You can also use the abstract keyword to describe a method that hasn’t been implemented yet—as a stub indicating “here is an interface method for all types inherited from this class, but at this point I don’t have any implementation for it.” An abstract method may be created only inside an abstract class. When the class is inherited, that method must be implemented, or the inheriting class becomes abstract as well. Creating an abstract method allows you to put a method in an interface without being forced to provide a possibly meaningless body of code for that method.
The interface keyword takes the concept of an abstract class one step further by preventing any method definitions at all. The interface is a very handy and commonly used tool, as it provides the perfect separation of interface and implementation. In addition, you can combine many interfaces together, if you wish, whereas inheriting from multiple regular classes or abstract classes is not possible.
tiger_wkh52741 2004-01-06
  • 打赏
  • 举报
回复
个人认为没有区别1
Yanbin_Q 2004-01-06
  • 打赏
  • 举报
回复
没什么区别

应该要问interface和abstract有什么区别

interface比abstract还要抽象,不能有默认实现。
lionqun 2004-01-06
  • 打赏
  • 举报
回复
你可以Implements interface1,interface2,interface3....
但是你不可以extends abstrct1,abstract2,abstract...
dhzsir 2004-01-06
  • 打赏
  • 举报
回复
没人,等待中。。。

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧