zoukankan      html  css  js  c++  java
  • Java类的成员函数调用顺序

     1 class A
     2 {
     3  public A()
     4  {
     5   System.out.println("----------A 构造-------------");
     6  }
     7  static  void sb()
     8  {
     9   System.out.println("----------A.sb() 静态块-------------");
    10  }
    11  {
    12   System.out.println("----------A 语句块-------------");
    13  }
    14 }
    15 
    16 class B extends A
    17 {
    18  public B()
    19  {
    20   System.out.println("----------B 构造-------------");
    21  }
    22  static void sb()
    23  {
    24   System.out.println("----------B.sb() 静态块-------------");
    25  }
    26  {
    27   System.out.println("----------B 语句块-------------");
    28  }
    29 }
    30 
    31 public class initSequence 
    32 {
    33  public static void main(String[] args)
    34  {
    35   System.out.println("First time new: ");
    36   B b=new B();
    37   System.out.println("Second time new: ");
    38   B b1=new B();
    39   System.out.println("Call the static functions:");
    40   A.sb();
    41   b.sb();
    42  }
    43 }

    输出:

    First time new:
    ----------A 语句块-------------
    ----------A 构造-------------
    ----------B 语句块-------------
    ----------B 构造-------------
    Second time new:
    ----------A 语句块-------------
    ----------A 构造-------------
    ----------B 语句块-------------
    ----------B 构造-------------
    Call the static functions:
    ----------A.sb() 静态块-------------
    ----------B.sb() 静态块-------------
  • 相关阅读:
    强大的C#图形处理组件
    Spring整合Mybatis的注意事项
    Umbraco常见陷阱与错误模式
    Umbraco 官网阅读理解
    Umbraco模型默认属性
    无缝隙滚动跑马灯组件
    这才是正确删除 office 的方式
    SVN利用Hooks自动发布网站
    Umbraco安装权限问题
    EPiServer网文
  • 原文地址:https://www.cnblogs.com/dracohan/p/4179475.html
Copyright © 2011-2022 走看看