java面向对象------super关键字使用

package java面向对象;

/**
* 测试super关键字
*/

public class TestSuper {
public static void main(String[] args) {
new childcla();
}
}


class fathercla{
public fathercla(){
System.out.println("输出fatherclass");
}
public void say(){
System.out.println("i love singing");
}
}

class childcla extends fathercla{
public childcla(){
super();//继承父类时,构造方法首先调用super(),不管你写还是不写
System.out.println("输出childclass");
super.say();//super可以直接调用父类的方法和属性
}
}

猜你喜欢

转载自www.cnblogs.com/zzzao/p/10890170.html