package coms;
/**
* super关键字
* super代表对象父类定义
*
*
*
*
* 每一个子类的构造方法在没有显示调用super(*),系统都会默认调用的super()
super(*) 必须书写在构造函数有效代码第一行
可以在子类构造方法中显示调用super(*),完成对特定父类构造方法的调用
* @author user
*
*/
public class javalx22 {
public static void main(String[] args) {
Sub a=new Sub();
a.print();
Dogh b=new Dogh();
System.out.println(b.sex);
}
}
//------------------------------------------
class Super{
int a =10;
}
class Sub extends Super{
int a=20;
public void print(){
System.out.println(a);
System.out.println(super.a);
}
}
//------------------------------------------
class Animalh{
String sex="asdfadsf";
public Animalh(){}
public Animalh(String sex){this.sex=sex;}
}
class Dogh extends Animalh{
public Dogh(){
super("maled");
}
}