class ExtendsDemo
{
public static void main (String[] args){
Zi zi = new Zi();
zi.show();
System.out.println("------");
Fu fu = new Fu();//创建父类的对象
fu.showFu();
}
}
class FuFu
{
int num=2;
}
class Fu extends FuFu
{
int num=10;
public void showFu(){
System.out.println(super.num);//第一种方式
}
}
class Zi extends Fu
{
int num=20;
public void show(){
int num=30;
System.out.println(num);//30
System.out.println(this.num);//20
System.out.println(super.num);//10
FuFu fufu=new FuFu();
int fufunum=fufu.num;//第二种方式
System.out.println(fufunum);
}
}
public Fu()
{
System.out.println("fu gouzao");//无参构造打印fu gouzao
}
public Fu(String s)
{
System.out.println("fu s = " + s);
System.out.println("--------------");
}
}
class Zi extends Fu
{
public Zi()
{
super("abc");//有参数就找父类的带参数的构造方法打印fu s=abc
System.out.println("Zi gouzao");//直接打印 Zi gouzao
}
public Zi(String s)
{
//super("abc");
//this();
System.out.println("Zi s = " + s);//输出Zi s=abc
System.out.println("************");
}
public Zi(String s, int a)
{
this(s);//找本类中的带一个参数的构造
System.out.println("Zi s = " + s);//最后执行这句打印 Zi s=abc
System.out.println("00000000000000");
}
}
class ExtendsDemo2
{
public static void main(String[] args)
{
Zi zi = new Zi("abc", 10);//第一步先找子类无参构造...........再找子类中带参数的构造
Fu f = new Fu();//招到无参的构造方法