标签:getname [] ext out rabbit extend 内存分配 代码 href
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 class Rabbit {
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");
// 父类的引用指向子类的对象
Tuzi p=new Tuzi0();
Tuzi0 a=new Tuzi0("xx","");
Rabbit b=new Rabbit();
b.showinfo(q);
b.maininfo(a);
}
}
父类引用指向子类的对象;
标签:getname [] ext out rabbit extend 内存分配 代码 href
原文地址:http://www.cnblogs.com/hljj/p/6880655.html