java为什么抛弃多类继承?
来源:互联网 发布:python echarts 编辑:程序博客网 时间:2024/04/30 14:02
主要是Java设计者希望Java是一个简单,友好的面向对象语言. 另外历史经验也表明C++的多类继承带来的复杂度远大于其好处.
Q: Why is multiple inheritance not provided in Java?
A: One of the main reasons for creating Java was to address the problems of C++. One such problem was multiple inheritance, which was prone to ambiguity when a class inherited from two separate classes which shared a function with an identical definition. The designers of Java decided to eliminate this problem altogether by only allowing a class to inherit from a single other concrete class.
Read more: http://wiki.answers.com/Q/Why_is_multiple_inheritance_not_provided_in_Java#ixzz1JTPK4ZHj
Q: Why doesn't the Java language support multiple inheritance?
A Whenever you find yourself asking why Java has or does not have some feature, consider the design goals behind the Java language. With that in mind, I started my search by skimming through "The Java Language Environment" by James Gosling and Henry McGilton (Sun Microsystems), a white paper published in May 1996 that explains some of the reasoning behind Java's design.
As the white paper states, the Java design team strove to make Java:
* Simple, object oriented, and familiar
* Robust and secure
* Architecture neutral and portable
* High performance
* Interpreted, threaded, and dynamic
The reasons for omitting multiple inheritance from the Java language mostly stem from the "simple, object oriented, and familiar" goal. As a simple language, Java's creators wanted a language that most developers could grasp without extensive training. To that end, they worked to make the language as similar to C++ as possible (familiar) without carrying over C++'s unnecessary complexity (simple).
In the designers' opinion, multiple inheritance causes more problems and confusion than it solves. So they cut multiple inheritance from the language (just as they cut operator overloading). The designers' extensive C++ experience taught them that multiple inheritance just wasn't worth the headache.
Note: For a discussion of the diamond problem, a classic multiple inheritance challenge, read Bill Venners's "Designing with Interfaces" (JavaWorld, December 1998) and Tony Sintes's "Java Diamonds Are Forever" (JavaWorld, March 2001).
Instead, Java's designers chose to allow multiple interface inheritance through the use of interfaces, an idea borrowed from Objective C's protocols. Multiple interface inheritance allows an object to inherit many different method signatures with the caveat that the inheriting object must implement those inherited methods.
Multiple interface inheritance still allows an object to inherit methods and to behave polymorphically on those methods. The inheriting object just doesn't get an implementation free ride. For an excellent discussion of interface inheritance, read Wm. Paul Rogers's "Reveal the Magic Behind Subtype Polymorphism" (JavaWorld, April 2001).
- java为什么抛弃多类继承?
- java 接口之多继承,类为什么不可以多继承
- java为什么不支持多继承
- Java为什么不支持多继承
- 为什么Java不支持多继承
- Java为什么不支持多继承
- java为什么不支持多继承
- 为什么Java不支持多继承?
- 为什么java没有多继承
- java为什么不支持多继承
- Java为什么不使用多继承
- Java中为什么没有多继承
- 为什么要抛弃HTML
- 为什么要抛弃HTML
- 为什么要抛弃HTML
- 为什么要抛弃maven
- java中的接口为什么可以多继承,而其他类则不能实现多继承
- java为什么搞单继承,多继承有什么坏处
- “ORA-06413:连接未打开”问题解决了,大家引以为戒吧
- flash与javacript:图片交互
- 好网站不是由采用哪种语言决定成功与否的
- Android平台中应该如何获取音乐文件的信息
- 关于SQL SERVER时间格式使用的一些总结
- java为什么抛弃多类继承?
- 要软考了啊w
- 使用Java调用以WSDL形式发布的web service
- see
- poi操作word文档
- 类类型
- 泡妞高手经典秘技之:日后再说
- Power Shell 学习笔记(二)所谓对象
- Qt Ui 头文件研究