public class Tuzi { //父类
public String name;
public void show(){
System.out.println(name+"是个笨蛋");
}
public Tuzi(){ } public Tuzi(String name){ this.name=name; }
public void setname(String name){ this.name=name; }
public String getname(){ return name; }
}
public class Tuzi0 extends Tuzi{ //子类
public String weight;
public Tuzi0(){
super();
}
public Tuzi0(String name,String weight){
super(name);
this.weight=weight;
}
public void main(){
System.out.println(name+"说,他承认自己是个笨蛋,并向你发出一拨666");
}
}
public String weight;
public Tuzi0(){
super();
}
public Tuzi0(String name,String weight){
super(name);
this.weight=weight;
}
public void main(){
System.out.println(name+"说,他承认自己是个笨蛋,并向你发出一拨666");
}
}
public class Rabbit {
public void showinfo(Tuzi q){
q.show();
}
public void maininfo(Tuzi0 a){
a.main();
}
}
public void showinfo(Tuzi q){
q.show();
}
public void maininfo(Tuzi0 a){
a.main();
}
}
public class Test2 {
public static void main(String[] args) {
Tuzi q=new Tuzi("xx");
public static void main(String[] args) {
Tuzi q=new Tuzi("xx");
// 父类的引用指向子类的对象
Tuzi p=new Tuzi0();
Tuzi0 a=new Tuzi0("xx","");
Rabbit b=new Rabbit();
b.showinfo(q);
b.maininfo(a);
}
}
Tuzi p=new Tuzi0();
Tuzi0 a=new Tuzi0("xx","");
Rabbit b=new Rabbit();
b.showinfo(q);
b.maininfo(a);
}
}