The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
Except for the 除了Object
class, a class has exactly one direct superclass. Object
类之外,一个类只有一个直接超类。A class inherits fields and methods from all its superclasses, whether direct or indirect. 类从它的所有超类继承字段和方法,无论是直接的还是间接的。A subclass can override methods that it inherits, or it can hide fields or methods that it inherits. 子类可以重写它继承的方法,也可以隐藏它继承的字段或方法。(Note that hiding fields is generally bad programming practice.)(请注意,隐藏字段通常是糟糕的编程实践。)
The table in Overriding and Hiding Methods section shows the effect of declaring a method with the same signature as a method in the superclass.重写和隐藏方法部分中的表显示了使用与超类中的方法相同的签名声明方法的效果。
The Object
class is the top of the class hierarchy. Object
类是类层次结构的顶部。All classes are descendants from this class and inherit methods from it. 所有类都是该类的后代,并从中继承方法。Useful methods inherited from 从对象继承的有用方法包括Object
include toString()
, equals()
, clone()
, and getClass()
.toString()
、equals()
、clone()
和getClass()
。
You can prevent a class from being subclassed by using the 通过在类的声明中使用final
keyword in the class's declaration. final
关键字,可以防止类被子类化。Similarly, you can prevent a method from being overridden by subclasses by declaring it as a final method.类似地,通过将方法声明为最终方法,可以防止子类重写该方法。
An abstract class can only be subclassed; it cannot be instantiated. 抽象类只能是子类;它不能被实例化。An abstract class can contain abstract methodsmethods that are declared but not implemented. 抽象类可以包含抽象方法已声明但未实现的方法。Subclasses then provide the implementations for the abstract methods.子类然后提供抽象方法的实现。