码迷,mamicode.com
首页 > 其他好文 > 详细

Interface VS Abstract Class

时间:2016-01-20 00:55:15      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

An abstract class can have shared state or functionality. An interface is only a promise to provide the state or functionality. A good abstract class will reduce the amount of code that has to be rewritten because it‘s functionality or state can be shared. The interface has no defined information to be shared.

  • Abstract class can have constants, members, defined methods and methods without body, while interface can only have constants and methods without body.
  • Interface can not have methods body, while abstract class can.
  • All methods in interface are defined as public, while in abstract class can be any visibility.
  • Classes implementing an interface must implement all its methods, while extending an abstract class only has to implement its abstract methods.
  • Child classes can define abstract methods with same or less restrictive visibility, while a class implementing an interface must define with the same visibility, which is public.
  • Classes can implement mutiple interfaces but only extends one class(abstract or concrete). Interfaces can also extend several interfaces.

Interface VS Abstract Class

标签:

原文地址:http://www.cnblogs.com/touchdown/p/5143796.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!