JAVA的继承初始化
程序员文章站
2024-02-17 17:49:40
...
初始化顺序
代码样例:
package com.imooc.second;
public class Telphone {
public int age;
public String name;
public void eat() {
System.out.print("这是的啥");
}
public Telphone() {
System.out.println("afff");
}
}
package com.imooc.second;
public class DOG extends Telphone{
public void eat() {
System.out.print("这是2265啥");
}
}
package com.imooc.second;
public class zhong {
public static void main(String[] args) {
// TODO Auto-generated method stub
DOG dog=new DOG();
dog.age=10;
dog.name = "xiaonian";
dog.eat();
}
}
输出结果:
afff
这是2265啥