欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

JAVA的继承初始化

程序员文章站 2024-02-17 17:49:40
...

初始化顺序JAVA的继承初始化

代码样例:

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