Java中继承的坏例子是什么? [英] What can be the bad example of inheritance in Java?
本文介绍了Java中继承的坏例子是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道Java中继承的优点,但我有点难以接受它也有缺点。任何人都可以在Java中给我一个糟糕的继承示例吗?
I know the advantages of inheritance in Java, but it is somewhat difficult for me to accept that it has disadvantages too. Can anybody give me a bad example of inheritance in Java?
推荐答案
-
Stack扩展了Vector
。堆栈不是矢量。 -
属性扩展Hashtable
。属性表不是哈希表。 Stack extends Vector
. A stack is not a vector.Properties extends Hashtable
. A table of properties is not a hash table.
参见这个答案来自Effective Java的报价。
See this answer for a quote from Effective Java.
这很容易使用已经在 Vector
中实现的内容编写 Stack
实现(同样用于属性
),但它产生了问题 - 见这里
It was easy to write the Stack
implementation by using what is already implemented in Vector
(likewise for Properties
), but it created problems - see here
这篇关于Java中继承的坏例子是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文