您好,欢迎访问一九零五行业门户网

Java中的super关键字

super 变量引用直接父类实例。super 变量可以调用直接父类方法。super() 充当直接父类构造函数,并且应该位于子类构造函数中的第一行。调用重写方法的超类版本时,使用 super 关键字。
示例 h2>现场演示
class animal { public void move() { system.out.println("animals can move"); }}class dog extends animal { public void move() { super.move(); // invokes the super class method system.out.println("dogs can walk and run"); }}public class testdog { public static void main(string args[]) { animal b = new dog(); // animal reference but dog object b.move(); // runs the method in dog class }}
输出这将产生以下结果 -
animals can movedogs can walk and run
以上就是java中的super关键字的详细内容。
其它类似信息

推荐信息