我们在java中
Java中初始化的顺寻?
java代码:
package sru.love.c; class Person { String name = "Person"; static { System.out.println("我是 Person 的 static 代码块"); } { System.out.println("我是 Person 构造代码块"); } Person() { System.out.println("我是person() 的无參构造函数!!"); } Person(String name) { this.name = name; } void show() { System.out.println(" Person 的名字"+this.name); } } class Student extends Person { int grade=2; static { System.out.println("我是 Student 的 static 代码块"); } { System.out.println("我是 Student 构造代码块"); } Student() { System.out.println("我的是Student 的无參构造函数! "); } Student(String name,int grade) { super(name); this.grade = grade; } void show() { System.out.println("我的几"+this.grade+"班的学生"); } } public class SuperDemo { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Student s = new Student(); s.show(); } }
运行结果: