- 1 1. 继承与 super 的关系
- 2 2. 如何使用 super(3 种核心模式)
- 3 3. 掌握 super 的实际示例
- 3.1 3.1 示例 1:构造函数调用顺序 (父类 → 子类)
- 3.2 3.2 示例 2:父类只有带参数的构造函数
- 3.3 3.3 Example 3: Calling a parent method after overriding (super.method())
- 3.4 3.4 Example 4: Accessing a hidden parent field (super.field)
- 3.5 3.5 Example 5: Calling both parent and child versions clearly
- 3.6 3.6 A realistic example: shared logic in the parent class
- 3.7 3.7 Section summary
- 4 4. Difference Between this and super
- 5 5. 常见错误与陷阱(如何避免错误)
- 6 6. 结论(关键要点)
- 7 7. 常见问题(FAQ)
- 7.1 7.1 在 Java 中何时应该使用 super?
- 7.2 7.2 如果我不写 super() 会发生什么?
- 7.3 7.3 super() 和 this() 有什么区别?
- 7.4 7.4 我可以在同一个构造函数中使用 this() 和 super() 吗?
- 7.5 7.5 我可以在静态方法中使用 super 吗?
- 7.6 7.6 super 会创建新的父对象吗?
- 7.7 7.7 如果我调用 super.method(),它总是只运行父类逻辑吗?
- 7.8 7.8 我应该经常使用 super.field 吗?
- 7.9 7.9 super 可以与接口一起使用吗?
- 7.10 7.10 掌握 super 的最快方式是什么?
1. 继承与 super 的关系
要理解 Java 的 super 关键字,首先需要了解 继承。
super 不是孤立记忆的东西——当你看到 子类和父类 如何协同工作时,它的含义就会变得清晰。
在本节中,你将学习什么是继承以及 super 最初为何存在,使用面向初学者的解释和简易代码示例。
1.1 Java 中的继承是什么?(extends 基础)
在 Java 中,继承 允许你基于已有类创建新类。
- 父类(超类):基础类
- 子类(子类):从父类继承的类
当子类扩展父类时,它可以复用父类的字段和方法,而无需重新编写它们。
基本继承语法(extends)
class Parent {
void hello() {
System.out.println("Hello from Parent");
}
}
class Child extends Parent {
}
这里,Child 继承了 Parent 的 hello() 方法。
public class Main {
public static void main(String[] args) {
Child child = new Child();
child.hello(); // calling a method inherited from Parent
}
}
输出:
Hello from Parent
因此即使 Child 没有定义 hello(),它仍然可以调用它,因为它已经继承了该方法。
1.2 为什么需要 super?
此时,你可能会想:
“如果子类已经继承了父类的所有内容,为什么还需要
super?”
在许多情况下,你 不必 明确写出 super。
然而,当你想 明确访问父类的版本 时,super 就变得必要。
常见情形包括:
- 子类 覆盖(override)了某个方法,但你仍想调用父类的版本
- 子类和父类拥有 相同名称的字段
- 需要使用参数调用 特定的父类构造函数
简而言之:
当你想显式引用 父类 时使用
super。
1.3 覆盖与 super(保留父类行为)
使用 super 最常见的原因之一是 方法覆盖。
覆盖意味着子类为父类中已存在的方法提供自己的实现。
示例:方法覆盖
class Parent {
void greet() {
System.out.println("Parent: Hello!");
}
}
class Child extends Parent {
@Override
void greet() {
System.out.println("Child: Hi!");
}
}
现在如果对 Child 对象调用 greet():
public class Main {
public static void main(String[] args) {
Child child = new Child();
child.greet();
}
}
输出:
Child: Hi!
子类版本会运行,因为覆盖让子类拥有优先权。
使用 super.greet() 调用父类版本
有时你并不想完全替代父类行为——只想 添加额外的逻辑。
这时 super.method() 就很有用:
class Parent {
void greet() {
System.out.println("Parent: Hello!");
}
}
class Child extends Parent {
@Override
void greet() {
super.greet(); // call parent version
System.out.println("Child: Hi!");
}
}
输出:
Parent: Hello!
Child: Hi!
这是一种非常实用的模式:
- 父类处理 通用行为
- 子类添加 自定义行为
1.4 当父类和子类拥有相同字段名时
另一个 super 重要的情形是父类和子类拥有 相同名称的字段。
示例:
class Parent {
int value = 100;
}
class Child extends Parent {
int value = 200;
void printValue() {
System.out.println(value);
}
}
这里,value 指的是 子类字段,因此输出将是:
200
如果您想访问父字段,请使用 super.value:
class Child extends Parent {
int value = 200;
void printValue() {
System.out.println(value); // child value
System.out.println(super.value); // parent value
}
}
输出:
200
100
关键要点:
value→ 子类字段super.value→ 父类字段
1.5 super 的真正含义(简单定义)
现在您可以这样总结 super:
super是一个关键字,它允许您显式访问字段、方法和构造函数的父类版本。
如果您只记住一行,就记住这一行:
super表示“使用父类版本”。
在下一节中,您将学习使用 super 的 3 种最重要的方式,每个方式都有清晰的示例。
2. 如何使用 super(3 种核心模式)
现在您已经理解了 super 的含义,让我们专注于它在 Java 中的实际使用方式。
在实际代码中,super 出现在三种主要模式中:
- 调用父构造函数(
super()/super(args...)) - 调用父方法(
super.method()) - 访问父字段(
super.field)
一旦您学会这三种,super 就会变得非常容易识别和正确使用。
2.1 调用父构造函数(super() / super(args...))
2.1.1 快速复习:什么是构造函数?
构造函数是一种特殊的方法,当您创建对象时它会运行。
class Person {
Person() {
System.out.println("Person constructor");
}
}
构造函数用于初始化,例如设置字段。
2.1.2 在继承中,父构造函数先运行
在 Java 继承中,创建子对象总是先初始化父部分。
这意味着:
父构造函数 → 子构造函数
示例:
class Parent {
Parent() {
System.out.println("Parent constructor");
}
}
class Child extends Parent {
Child() {
System.out.println("Child constructor");
}
}
public class Main {
public static void main(String[] args) {
new Child();
}
}
输出:
Parent constructor
Child constructor
即使我们没有编写 super(),父构造函数仍然运行了。
2.1.3 super() 会自动插入(当可能时)
如果父类有无参构造函数,Java 会自动在子构造函数的顶部插入这一行:
super();
因此,这两个构造函数实际上是相同的:
Child() {
System.out.println("Child constructor");
}
Child() {
super(); // implicitly inserted by the compiler
System.out.println("Child constructor");
}
2.1.4 当父类只有带参构造函数时
这是初学者最常见的错误之一。
如果父类没有无参构造函数,Java 无法自动插入 super()。
示例(这将导致编译错误):
class Parent {
Parent(int x) {
System.out.println("Parent: " + x);
}
}
class Child extends Parent {
Child() {
System.out.println("Child created");
}
}
失败原因:
- 编译器试图插入
super(); - 但
Parent()不存在
✅ 修复:显式调用正确的父构造函数
class Child extends Parent {
Child() {
super(10);
System.out.println("Child created");
}
}
输出:
Parent: 10
Child created
2.1.5 super(...) 必须是构造函数中的第一行
Java 要求 super(...) 是构造函数中的第一条语句。
❌ 错误:
Child() {
System.out.println("Something first");
super(10); // compile error
}
✅ 正确:
Child() {
super(10);
System.out.println("Child logic");
}
原因:
- 父类必须先初始化,然后子类才能安全地运行其自身逻辑。
2.2 调用父类方法 (super.method())
另一个非常常见的用例是在重写后调用父类方法。
2.2.1 基本示例
class Parent {
void show() {
System.out.println("Parent show()");
}
}
class Child extends Parent {
@Override
void show() {
System.out.println("Child show()");
}
void test() {
super.show(); // parent version
show(); // child version
}
}
public class Main {
public static void main(String[] args) {
new Child().test();
}
}
输出:
Parent show()
Child show()
2.2.2 何时使用此功能?
super.method() 在以下情况下很有用:
- 父类方法包含公共逻辑
- 子类方法需要扩展行为而不是替换它
- 您想避免将父类逻辑复制粘贴到子类中
示例:
class Parent {
void process() {
System.out.println("Common processing");
}
}
class Child extends Parent {
@Override
void process() {
super.process();
System.out.println("Child-specific processing");
}
}
这种模式可以保持您的代码干净且易于维护。
2.3 访问父类字段 (super.field)
字段的工作方式类似。如果父类和子类都有同名字段,则子类字段会隐藏父类字段。
示例:
class Parent {
int value = 100;
}
class Child extends Parent {
int value = 200;
void print() {
System.out.println(value); // child field
System.out.println(super.value); // parent field
}
}
public class Main {
public static void main(String[] args) {
new Child().print();
}
}
输出:
200
100
2.3.1 在实际项目中应该这样做吗?
通常,在父类和子类中使用相同的字段名不是一个好主意,因为它可能会迷惑读者。
但是,在以下情况下可能会发生:
- 您正在维护遗留代码
- 您被迫匹配现有的父类设计
- 您需要明确区分父类与子类值
在这些情况下,super.field 是正确的工具。
2.4 三种模式的总结
您可以这样记住 super:
super()/super(args...)→ 调用父类构造函数super.method()→ 调用父类方法super.field→ 访问父类字段
在下一节中,我们将通过实际代码示例深入探讨,以便您清楚地看到这些模式在执行时的行为。
3. 掌握 super 的实际示例
此时,您已经了解了使用 super 的三种核心方式。
现在,让我们通过实际示例来让这些知识牢固地掌握。
本节重点关注:
- 执行顺序
- 调用什么以及为什么
super如何在实际代码中改变行为
3.1 示例 1:构造函数调用顺序 (父类 → 子类)
最重要的规则要记住:
在创建子类对象时,Java 总是先初始化父类部分。
class Parent {
Parent() {
System.out.println("Parent constructor");
}
}
class Child extends Parent {
Child() {
super(); // optional here, but allowed
System.out.println("Child constructor");
}
}
public class Main {
public static void main(String[] args) {
new Child();
}
}
输出:
Parent constructor
Child constructor
关键点:
即使您移除 super(),结果也是一样的(前提是父类有无参构造函数)。
3.2 示例 2:父类只有带参数的构造函数
如果父类没有无参构造函数,则子类必须显式调用正确的构造函数。
class Parent {
Parent(String name) {
System.out.println("Parent: " + name);
}
}
class Child extends Parent {
Child() {
super("Taro");
System.out.println("Child created");
}
}
public class Main {
public static void main(String[] args) {
new Child();
}
}
Output:
Parent: Taro
Child created
Key point:
If you forget super("Taro"), Java tries to insert super() automatically and fails.
3.3 Example 3: Calling a parent method after overriding (super.method())
This is one of the most useful patterns in real projects.
class Parent {
void greet() {
System.out.println("Hello from Parent");
}
}
class Child extends Parent {
@Override
void greet() {
super.greet(); // call parent behavior
System.out.println("Hello from Child");
}
}
public class Main {
public static void main(String[] args) {
new Child().greet();
}
}
Output:
Hello from Parent
Hello from Child
Key point:
You can extend parent behavior without rewriting it.
3.4 Example 4: Accessing a hidden parent field (super.field)
If parent and child both define a field with the same name, the child version hides the parent version.
class Parent {
int value = 100;
}
class Child extends Parent {
int value = 200;
void printValues() {
System.out.println("Child value: " + value);
System.out.println("Parent value: " + super.value);
}
}
public class Main {
public static void main(String[] args) {
new Child().printValues();
}
}
Output:
Child value: 200
Parent value: 100
Key point:
valuerefers to the child’s fieldsuper.valuerefers to the parent’s field
3.5 Example 5: Calling both parent and child versions clearly
This is a great example to remove confusion.
class Parent {
void show() {
System.out.println("Parent show()");
}
}
class Child extends Parent {
@Override
void show() {
System.out.println("Child show()");
}
void test() {
super.show(); // parent version
this.show(); // child version (same as just calling show())
}
}
public class Main {
public static void main(String[] args) {
new Child().test();
}
}
Output:
Parent show()
Child show()
Key point:
super.show()= parentthis.show()= child
3.6 A realistic example: shared logic in the parent class
In real applications, parent classes often contain common logic such as logging, validation, or setup steps.
class BaseService {
void execute() {
System.out.println("[LOG] Start execution");
}
}
class UserService extends BaseService {
@Override
void execute() {
super.execute(); // reuse shared behavior
System.out.println("UserService logic running...");
}
}
public class Main {
public static void main(String[] args) {
new UserService().execute();
}
}
Output:
[LOG] Start execution
UserService logic running...
Why this is useful:
- You avoid duplicating common behavior
- The child focuses only on what’s unique
- Your code becomes easier to maintain
3.7 Section summary
From these examples, you should remember:
- Parent constructors run before child constructors
super(args...)is required if the parent has no no-arg constructorsuper.method()is perfect for reusing and extending behaviorsuper.fieldhelps when parent and child fields share the same name
Next, we’ll clarify one of the most confusing topics for beginners:
What’s the difference between
thisandsuper?
4. Difference Between this and super
When learning Java’s super, you will almost always see this at the same time.
Both are reference keywords, so it’s easy for beginners to mix them up.
In this section, you’ll learn:
markdown.* 什么是 this * 什么是 super * 如何在字段、方法和构造函数中正确使用它们
4.1 this 指向当前对象(子类实例)
this 的含义:
“当前对象实例”
它最常在字段名与构造函数参数名相同的情况下使用。
class User {
String name;
User(String name) {
this.name = name; // field = parameter
}
}
这里:
name(右侧)是构造函数参数this.name(左侧)是实例字段
因此 this 可以帮助你避免混淆。 
4.2 super 指向父类一侧
super 指的是当前对象中父类(超类)的部分。
它的含义:
“使用父类的实现”
当你想访问被隐藏或被覆盖的父类成员时,通常会使用它。
4.3 记忆区别的最简方法
面向初学者的记忆方式:
this→ 子类一侧super→ 父类一侧
它们不是两个不同的对象。
它们是同一个对象的两个不同“视图”。
4.4 在字段中使用 this 与 super
如果父类和子类都定义了同名字段,你可以明确选择想要使用的那个。
class Parent {
int value = 100;
}
class Child extends Parent {
int value = 200;
void print() {
System.out.println(this.value); // child field
System.out.println(super.value); // parent field
}
}
public class Main {
public static void main(String[] args) {
new Child().print();
}
}
输出:
200
100
关键点:
this.value= 子类字段super.value= 父类字段
另外,在 Java 中,this 往往是可选的:
System.out.println(value);
等价于:
System.out.println(this.value);
4.5 在方法中使用 this 与 super
方法是 this 与 super 区别最常出现的地方——尤其是在重写时。
class Parent {
void show() {
System.out.println("Parent show()");
}
}
class Child extends Parent {
@Override
void show() {
System.out.println("Child show()");
}
void test() {
this.show(); // child method (same as show())
super.show(); // parent method
}
}
public class Main {
public static void main(String[] args) {
new Child().test();
}
}
输出:
Child show()
Parent show()
关键点:
this.show()→ 子类实现super.show()→ 父类实现
4.6 构造函数:this() 与 super()
这是初学者最容易混淆的部分,但非常重要。
this()调用 同一类中的另一个构造函数super()调用 父类中的构造函数
4.6.1 this() 示例(同类内部的构造函数链)
class User {
String name;
int age;
User() {
this("NoName", 0); // call another constructor
}
User(String name, int age) {
this.name = name;
this.age = age;
}
}
这很有用,因为它避免了重复的初始化逻辑。
4.6.2 super() 示例(调用父类构造函数)
class Parent {
Parent() {
System.out.println("Parent constructor");
}
}
class Child extends Parent {
Child() {
super(); // initialize parent
System.out.println("Child constructor");
}
}
输出:
Parent constructor
Child constructor
4.7 不能同时使用 this() 和 super()
许多初学者会尝试这样写:
Child() {
this(1);
super(); // error
}
这是不允许的。
原因:
this()与super()必须是构造函数中的 第一行- 两者只能选其一作为第一行
因此必须二选一。
4.8 重要提醒:super 并不会创建新对象
.super 并不会创建一个独立的父对象。
相反:
this= 作为子类视角的当前对象super= 作为父类视角的同一对象
这就是为什么 super 最好被视为一个引用关键字,而不是对象创建者。
4.9 小节总结
this指向当前对象(子类侧)super指向父类侧this()调用同一个类中的另一个构造函数super()调用父类的构造函数this()与super()不能同时使用
接下来,我们将介绍常见错误和错误模式,帮助你避免最常见的初学者陷阱。
5. 常见错误与陷阱(如何避免错误)
Java 的 super 关键字功能强大,但也很容易被误用——尤其是在你仍在学习继承和构造函数时。
在本节中,你将学习初学者最常犯的错误以及如何快速修复它们。
5.1 在错误的位置写 super(...)(构造函数规则)
最重要的规则之一:
super(...)必须是构造函数内部的第一条语句。
❌ 错误(编译错误):
class Parent {
Parent(int x) {}
}
class Child extends Parent {
Child() {
System.out.println("Do something first");
super(10); // ERROR: must be first line
}
}
✅ 正确:
class Child extends Parent {
Child() {
super(10);
System.out.println("Child logic");
}
}
为什么?
因为对象的父类部分必须在子类逻辑运行之前完成初始化。
5.2 当父类没有无参构造函数时忘记写 super(args…)
如果父类只有带参构造函数,Java 无法自动插入 super()。
❌ 错误:
class Parent {
Parent(String name) {}
}
class Child extends Parent {
Child() {
// compiler tries to insert super() here -> ERROR
}
}
✅ 正确:
class Child extends Parent {
Child() {
super("Taro");
}
}
这是初学者非常常见的编译错误,所以一定要检查父类的构造函数。
5.3 在同一个构造函数中同时使用 this() 与 super()
初学者常常会想:
“我想调用另一个构造函数 并且 调用父构造函数。”
但 Java 不允许这样做。
❌ 错误:
class Parent {
Parent() {}
}
class Child extends Parent {
Child() {
this(1);
super(); // ERROR
}
Child(int x) {}
}
原因:
this()与super()必须都是 第一行- 只能有一个是第一行
因此,你必须设计构造函数,使得只能直接使用其中一个。
5.4 在静态方法中使用 super
super 与当前对象实例绑定,所以在静态方法中无效。
❌ 错误(概念上):
class Parent {
void hello() {}
}
class Child extends Parent {
static void test() {
super.hello(); // ERROR
}
}
关键点:
- 静态方法属于类本身,而不是某个实例
super指向实例的父类部分
因此 Java 会阻止这种用法。
5.5 把 super 误解为“创建父对象”
一些初学者会认为:
“使用
super会创建一个独立的父对象。”
这并不正确。
super 不会 创建新对象。
它仅仅是访问同一对象的父类侧。
可以这样理解:
this= 同一对象,子类视角super= 同一对象,父类视角
5.6 过度使用 super.field(字段隐藏通常是不好的做法)
是的,super.field 是可以使用的——但在大多数真实项目中,你应该避免在父子类中使用相同名称的字段。
示例(设计混乱):
class Parent {
int value = 100;
}
class Child extends Parent {
int value = 200; // hides parent field
}
虽然 super.value 能工作,但这种设计会让代码更难阅读和维护。
更好的实践:
answer.* 使用不同的字段名 * 将字段设为私有,并通过方法(getter)公开 * 除非绝对必要,否则避免隐藏字段
5.7 “如果我调用 super.method(),只有父类逻辑会运行”(并非总是如此)
这稍微有点进阶,但很有用。
当你调用 super.method() 时,确实调用的是父类的方法。
然而,在那个父类方法内部,如果它调用了子类覆盖的另一个方法,则可能会运行子类的实现。
示例:
class Parent {
void a() {
b(); // calls b()
}
void b() {
System.out.println("Parent b()");
}
}
class Child extends Parent {
@Override
void b() {
System.out.println("Child b()");
}
}
public class Main {
public static void main(String[] args) {
Child c = new Child();
c.a();
}
}
输出:
Child b()
即使 a() 位于父类,它会调用 b(),而 b() 在子类中被覆盖。
初学者要点:
super.method() 调用该方法的父类实现,但其中的 内部 方法调用仍然遵循覆盖规则。
5.8 快速检查清单(避免初学者错误)
在使用 super 之前,请检查以下事项:
super(...)是否是构造函数中的第一行?- 父类是否有无参构造函数?
- 你是否尝试同时使用
this()和super()? - 你是否在静态方法中使用
super? - 你是否不必要地隐藏了同名字段?
6. 结论(关键要点)
在本文中,你了解了 Java 的 super 关键字是什么、它为何存在,以及如何在实际代码中正确使用它。
让我们总结一下你应该记住的最重要的要点。
6.1 super 在 Java 中意味着什么?
super 是一个关键字,允许你显式访问对象的 父类(超类) 部分。
它主要在继承(extends)时使用,当你想引用父类的版本时:
- 构造函数
- 方法
- 字段
简单来说:
super的意思是“使用父类的实现”。
6.2 使用 super 的三种最重要方式
你可以通过以下三种模式记住 super:
1) 调用父类构造函数
super()super(args…)
当你需要正确初始化父类时使用,尤其是父类需要参数时。
2) 调用父类方法
super.method()
当你覆盖了方法但仍想复用父类行为时很有用。
3) 访问父类字段
super.field
当父类和子类都有同名字段且你想明确引用父类的字段时使用。
6.3 this 与 super(最简易的理解方式)
许多初学者会混淆这两个关键字,但区别很简单:
this→ 当前对象(子类视角)super→ 同一对象的父类视角
它们 不 代表两个不同的对象。
6.4 大多数错误出现在构造函数周围
如果想避免最常见的错误,请记住以下规则:
super(...)必须是构造函数中的 第一行- 如果父类没有无参构造函数,你必须写
super(args…) - 不能在同一个构造函数中同时使用
this()和super() super在静态方法中无效
6.5 最后要点:super 帮助你安全地复用和扩展父类逻辑
super 的真正力量在于它让你能够:
- 将共享逻辑保留在父类中
- 在子类中扩展行为
- 避免复制粘贴代码
- 让继承更清晰、更易维护
如果你只能记住本文的一句话,请记住:
super是当你想要 父类实现 时使用的关键字。
7. 常见问题(FAQ)
这是初学者在学习 Java 的 super 关键字时最常问的问题。
如果你对某些部分仍然感到不确定,本节应该能快速澄清。
7.1 在 Java 中何时应该使用 super?
你通常在这些情况下使用 super:
- 当你想调用父类构造函数时(
super()/super(args...)) - 当你重写方法但仍想调用父类方法时(
super.method()) - 当父类和子类有相同的字段名且你想要父类字段时(
super.field)
对于初学者,最常见和有用的情况是:
重写方法并使用
super.method()调用父类逻辑。
7.2 如果我不写 super() 会发生什么?
如果父类有无参构造函数,Java 会自动插入:
super();
在子类构造函数的顶部。
因此,在许多情况下,你不需要手动编写它。
但是,如果父类没有无参构造函数,除非你显式使用参数调用正确的构造函数,否则代码会失败。
7.3 super() 和 this() 有什么区别?
它们调用不同的构造函数:
super()→ 调用父类中的构造函数this()→ 调用同一类中的构造函数
示例想法:
- 使用
this()来减少重复的构造函数代码 - 使用
super()来正确初始化对象的父类部分
7.4 我可以在同一个构造函数中使用 this() 和 super() 吗?
不可以。
原因:
this()和super()都必须是构造函数中的第一条语句- 只有一条语句可以是第一条
因此,Java 强制你选择其中一个。
7.5 我可以在静态方法中使用 super 吗?
不可以(通常)。
super 与当前对象实例相关,但静态方法属于类本身,并且没有实例引用。
这就是为什么在静态方法中使用 super 会导致编译错误。
7.6 super 会创建新的父对象吗?
不会。
super 不会创建任何新对象。
它只是访问同一对象的父类视图。
一种有帮助的思考方式:
this= 作为子类查看的同一对象super= 作为父类查看的同一对象
7.7 如果我调用 super.method(),它总是只运行父类逻辑吗?
super.method() 总是调用该方法的父类版本。
但是,如果父类方法内部调用另一个子类重写的方法,那么由于 Java 的重写规则,子类版本可能会运行。
初学者级别的要点:
super.method()调用父类版本,但其中的方法调用仍可能受重写影响。
7.8 我应该经常使用 super.field 吗?
通常,不应该。
如果你经常需要 super.field,这可能意味着你的设计令人困惑,因为父类和子类共享相同的字段名。
在实际项目中,除非有强有力的理由(如遗留代码或外部约束),最好避免字段隐藏。
7.9 super 可以与接口一起使用吗?
在正常的继承(extends)中,super 指的是父类。
但是,Java 还允许一种特殊的语法来调用接口默认方法:
InterfaceName.super.method();
这是更高级的内容,所以如果你是初学者,先专注于:
- 类继承
super()/super.method()/super.field
7.10 掌握 super 的最快方式是什么?
一个简单的学习路径:
- 编写一个基本的父子类并确认构造函数顺序
- 重写一个方法并调用
super.method() - 使用字段和方法比较
this与super - 练习修复与构造函数相关的错误
最好的实践是编写小示例并运行它们。

