class Demo{
static{
System.out.println("zhu静态代码块...");
}
{
System.out.println("zhu构造代码块 ...");
}
public static void main(String[] args) {
{
System.out.println("zhu局部代码块 ...");
}
int x = 1;
System.out.println("x= "+x);
new Demo();
Zi z = new Zi();
z.showFu();
z.showZi();
System.out.println("--------------");
Zi z1 = new Zi(17);
z1.showFu();
z1.showZi();
}
}
class Fu{
static int x = 1;
private int age = 1;
static{
System.out.println("Fu静态代码块...");
}
{
System.out.println("Fu构造代码块 ...");
}
public Fu() {
System.out.println("Fu类无参构造···");
}
public Fu(int age) {
this.age = age;
System.out.println("Fu类有参构造···");
}
public void showFu() {
System.out.println("Fu类成员方法 ...");
{
System.out.println("Fu局部代码块 ...");
}
}
}
class Zi extends Fu {
static{
System.out.println("Zi静态代码块...");
}
{
System.out.println("Zi构造代码块 ...");
}
public Zi() {
System.out.println("zi类无参构造···");
}
public Zi(int age) {
super(age);
System.out.println("zi类有参构造···");
}
public void showZi() {
System.out.println("Zi类成员方法...");
{
System.out.println("Zi局部代码块 ...");
}
}
}
|
|