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() 静态块-------------
  • 相关阅读:
    jdk动态代理底层实现
    SpringMvc执行流程及底层代码流程
    JavaWeb02-JSP数据交互
    JavaWeb01-动态网页
    异常总结
    优雅代码
    flask 脚本迁移语句
    git 拉取分支合并master&&回滚
    创建型设计模式
    基于mybatis的一个分表插件
  • 原文地址:https://www.cnblogs.com/dracohan/p/4179475.html
Copyright © 2011-2022 走看看