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.
摘要: C++支持类的多继承,而Java采用类的单继承。类的多继承有其灵活性,但语义复杂给使用带来了困难。Java中引入了接口,接口中定义了一组协议规范,即方法原型。将方法的实现部分推迟到类中完成,从而将接口继承与实现继承分开。接口继承可以间接替代多继承,具有多继承的优点,而且使用简单。
关键词:
继承,
多继承,
接口,
实现
CLC Number:
Li Huiqi, Li Yuqian. Comparis on of the Inheritance Mechanism in C++ and Java[J]. , 1997, 23(S1): 250-253.
李慧琪,李玉茜. C++和Java继承机制的比较[J]. , 1997, 23(S1): 250-253.