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() 静态块-------------
  • 相关阅读:
    Generate SQL from Excel
    ASP.NET Web API系列教程目录
    进阶篇:以IL为剑,直指async/await
    30分钟?不需要,轻松读懂IL
    进程简介
    二维码详解
    通过IL分析C#中的委托、事件、Func、Action、Predicate之间的区别与联系
    我是一个线程
    ServiceLocator 简单示例(转)
    特性(C#)
  • 原文地址:https://www.cnblogs.com/dracohan/p/4179475.html
Copyright © 2011-2022 走看看