zoukankan      html  css  js  c++  java
  • 当多个类之间有继承关系时,创建子类对象会导致父类初始化块的执行。

    源代码

    public class inherit {

    public static void main(String[] args){

    first a=new first();

    a.show();

    }

    }

    class second{

    String name;

    {

    name="zxr";

    }

    }

    class first extends second{

    int age=20;

    void show()

    {

    System.out.println("名字"+name);

    System.out.println("年龄"+age);

    }

    }

  • 相关阅读:
    hdu1507
    zoj1654
    hdu2444
    poj3692
    hdu1150
    hdu1151
    poj2771
    hdu3829
    hdu4619
    hdu4715
  • 原文地址:https://www.cnblogs.com/zxr-1996/p/4888471.html
Copyright © 2011-2022 走看看