leon_sandy的专栏

我曾为时光的流逝而哭泣

Chapter 6:Inheritance and Composition



 Insect {
   i = 9;
   j;
  Insect() {
    prt( + i +  + j);
    j = 39;
  }
    x1 = 
    prt();
    prt(String s) {
    System.out.println(s);
     47;
  }
}

  Beetle  Insect {
   k = prt();
  Beetle() {
    prt( + k);
    prt( + j);
  }
    x2 =
    prt();
    prt(String s) {
    System.out.println(s);
     63;
  }
     main(String[] args) {
    prt();
    Beetle b =  Beetle();
  }
} 

该程序的输出如下:
 Insect.x initialized
 Beetle.x initialized
Beetle constructor
i = 9, j = 0
Beetle.k initialized
k = 63
j = 39
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭