It all boils down to the question how you define the term "inheritance".
An instance of a class can be called not only with its own methods, but also with all methods declared in any of its superclasses. Would you like to call that "inheritance"? The Java community does so.
An instance of a class does not only have the fields that it declared itself, but also all fields declared in any of its superclasses. Would you like to call that "inheritance"? The Java community does so.
A subclass implicitly has all the characteristics of its superclass, e.g. which interfaces it implements. Would you like to call that "inheritance"? The Java community does so.
A class implementing an interface will have all the methods declared in the interface. Would you like to call that "inheritance"? The Java community calls this "implementing an interface", not "inheritance". [I'm a bit surprised that the Oracle book seems to use the term "inheritance" here as well.]
In a class implementing an interface, you can access constants declared in the interface by their simple name, without the need to prefix the constant with the interface name. Would you like to call that "inheritance"? The Java community does not, it's just a shorthand notation.
When importing a package like import java.awt.*, you can then access classes by their simple name, without the need to prefix them with their package name. Would you like to call that "inheritance"? The Java community does not, it's just a shorthand notation.
Of course, you can call any of these (and many more) language features by any name you like, but don't be surprised if it causes misunderstandings.
发布评论
评论(1)
这一切都归结为您如何定义“继承”一词的问题。
类的实例不仅可以使用其自己的方法来调用,而且可以使用其任何超类中声明的所有方法来调用。您想称之为“继承”? Java社区这样做。
类的实例不仅具有其声明的字段,而且在其任何超类中都声明了所有字段。您想称之为“继承”? Java社区这样做。
一个子类隐含其超级类的所有特征,例如它所实现的。您想称之为“继承”? Java社区这样做。
实现接口的类将在接口中声明所有方法。您想称之为“继承”? Java社区称此“实现接口”,而不是“继承”。 [我有些惊讶的是,Oracle书似乎也使用“继承”一词。]
当导入
导入java.aw.*
之类的软件包时,您可以通过其简单名称访问类,而无需将它们带有其包装名称。您想称之为“继承”? Java社区没有,这只是速记符号。当然,您可以用您喜欢的任何名字来调用这些(以及更多)语言功能,但如果引起误解,请不要感到惊讶。
It all boils down to the question how you define the term "inheritance".
An instance of a class can be called not only with its own methods, but also with all methods declared in any of its superclasses. Would you like to call that "inheritance"? The Java community does so.
An instance of a class does not only have the fields that it declared itself, but also all fields declared in any of its superclasses. Would you like to call that "inheritance"? The Java community does so.
A subclass implicitly has all the characteristics of its superclass, e.g. which interfaces it implements. Would you like to call that "inheritance"? The Java community does so.
A class implementing an interface will have all the methods declared in the interface. Would you like to call that "inheritance"? The Java community calls this "implementing an interface", not "inheritance". [I'm a bit surprised that the Oracle book seems to use the term "inheritance" here as well.]
In a class implementing an interface, you can access constants declared in the interface by their simple name, without the need to prefix the constant with the interface name. Would you like to call that "inheritance"? The Java community does not, it's just a shorthand notation.
When importing a package like
import java.awt.*
, you can then access classes by their simple name, without the need to prefix them with their package name. Would you like to call that "inheritance"? The Java community does not, it's just a shorthand notation.Of course, you can call any of these (and many more) language features by any name you like, but don't be surprised if it causes misunderstandings.