继承的初始化

继承初始化:
我们有必要对整个初始化过程有所认识,其中包括继承,对这个过程中发生的事情有一个整体性的概念。请观察下述代码:

package com.test.mianshi;

class Insect {
  
int i = 9;
  
int j;

  Insect() {
    prt(
"i = " + i + ", j = " + j);
    j = 39;
  }

  
static int x1 = prt("static Insect.x1 initialized");

  
static int prt(String s) {
    System.out.println(s);
    
return 47;
  }
}

public class Beetle extends Insect {
  
int k = prt("Beetle.k initialized");

  Beetle() {
    prt(
"k = " + k);
    prt(
"j = " + j);
  }

  
static int x2 = prt("static Beetle.x2 initialized");

  
static int prt(String s) {
    System.out.println(s);
    
return 63;
  }

  
public static void main(String[] args) {
    prt(
"Beetle constructor");
    Beetle b =
 new Beetle();
  }
}
 // /:~

你可能感兴趣的:(java)