作者投稿和查稿 主编审稿 专家审稿 编委审稿 远程编辑

›› 1997, Vol. 23 ›› Issue (S1): 250-253.

• 论文 • 上一篇    下一篇

C++和Java继承机制的比较

李慧琪,李玉茜   

  1. 华东师范大学计算机系,华东师范大学计算机系 上海 200062,上海 200062
  • 发布日期:1997-12-29

Comparis on of the Inheritance Mechanism in C++ and Java

Li Huiqi, Li Yuqian   

  1. (Computer Science Department, East China Normal University Shanghai 200062)
  • Published:1997-12-29

摘要: C++支持类的多继承,而Java采用类的单继承。类的多继承有其灵活性,但语义复杂给使用带来了困难。Java中引入了接口,接口中定义了一组协议规范,即方法原型。将方法的实现部分推迟到类中完成,从而将接口继承与实现继承分开。接口继承可以间接替代多继承,具有多继承的优点,而且使用简单。

关键词: 继承, 多继承, 接口, 实现

Abstract: C++ uses multiple inheritance, while Java discards multiple inheritance of class. However, Java introduces interface, which solves many of the problems for which multiple inheritance has been found to be useful. Interfaces are protocol specifications which define prototypes of methods without implementations. The implementing parts are deferred until a class implements the interface. The seperation of interface and implementation results in the independent interface inheritance. Hence, the inheritance provided by interface is much simpler and more flexible than multiple inheritance of class.

中图分类号: