- public class A {
- static class R{
-
- void t(){
- System.out.println("R.t");
- }
-
- public R() {
- System.out.println("R before");
- t();
- System.out.println("R after");
- }
- }
-
- static class Rr extends R{
- private int n = 1;
- void t(){
- System.out.println("Rr.t");
- System.out.println("Rr.n : " + this.n);
- }
-
- public Rr(int n) {
- System.out.println("Rr before");
- this.n = n;
- System.out.println("Rr.n : " + this.n);
- System.out.println("Rr after");
- }
- }
-
- public static void main(String[] args) {
-
- new Rr(3);
- }
- }
复制代码 R before
Rr.t
Rr.n : 0
R after
Rr before
Rr.n : 3
Rr after
1、解释一下输出过程? 2、为什么黑色粗体能执行n的值是0?Rr的t为什么可以在Rr的初始化方法前执行?
|