java基础之父类子类,static步骤,构造函数 编译调用的优先顺序
java基础之父类子类,static方法,构造函数 编译调用的优先顺序
package dd;
class Person {
Person() {
System.out.println("Person...");
}
// 隐式方法
{
System.out.println("Person hello...");
}
static {
System.out.println("Person static...");
}
}
public class Test extends Person {
Test() {
System.out.println("Test...");
}
{
System.out.println("hello...");
}
static {
System.out.println("static...");
}
public static void main(String[] args) {
System.out.println("main...");
new Test();
}
}
// Person static...
// static...
// main...
// Person hello...
// Person...
// hello...
// Test...
// 编译过程
// 1.父类静态属性
// 2.父类静态方法体
// 3.子类静态属性
// 4.子类静态方法体
// 5.父类非静态属性
// 6.父类非静态:隐式方法
// 7.父类构造函数
// 8.子类非静态属性
// 9.子类非静态:隐式方法
// 10.子类构造函数
转载自:http://blog.****.net/huaqi2820/article/details/5143928
package dd;
class Person {
Person() {
System.out.println("Person...");
}
// 隐式方法
{
System.out.println("Person hello...");
}
static {
System.out.println("Person static...");
}
}
public class Test extends Person {
Test() {
System.out.println("Test...");
}
{
System.out.println("hello...");
}
static {
System.out.println("static...");
}
public static void main(String[] args) {
System.out.println("main...");
new Test();
}
}
// Person static...
// static...
// main...
// Person hello...
// Person...
// hello...
// Test...
// 编译过程
// 1.父类静态属性
// 2.父类静态方法体
// 3.子类静态属性
// 4.子类静态方法体
// 5.父类非静态属性
// 6.父类非静态:隐式方法
// 7.父类构造函数
// 8.子类非静态属性
// 9.子类非静态:隐式方法
// 10.子类构造函数
转载自:http://blog.****.net/huaqi2820/article/details/5143928