在 Java 中,“Super 超类”通常是指在继承关系中被继承的类,也就是父类( superclass),而 super 是 Java 中的一个关键字,用来引用父类的成员或构造方法。
下面分开说明:
超类 = 父类 = 基类
class Animal { // 超类
void eat() {
System.out.println("吃东西");
}
}
class Dog extends Animal { // Dog 是子类
}
Animal 是 超类Dog 是 子类super 不是“类”,而是关键字,用于:
class Animal {
Animal(String name) {
System.out.println(name);
}
}
class Dog extends Animal {
Dog() {
super("狗"); // 调用父类构造方法
}
}
✅ 必须是子类构造方法的第一行
class Animal {
void sound() {
System.out.println("动物叫");
}
}
class Dog extends Animal {
void sound() {
super.sound(); // 调用父类方法
System.out.println("汪汪");
}
}
class Animal {
String name = "动物";
}
class Dog extends Animal {
String name = "狗";
void show() {
System.out.println(super.name); // 动物
}
}
❌ super 是一个类
✅ super 是关键字,表示“父类对象引用”
❌ 超类一定是抽象类
✅ 超类可以是普通类、抽象类或接口(接口叫父接口)
Super 超类是指被继承的父类,而
super是用来访问父类构造方法、方法和属性的关键字。
如果你是在学 继承 / 构造方法 / 面试题,我可以给你画个关系图或出几道练习题。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。