• 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() 静态块-------------
  • 相关阅读:
    JAVA微信公众号网页开发——获取公众号关注的所有用户
    删除mysl
    sql语言(mysql)
    mycat读写分离
    mysql双主双从技术
    实用的10个日志处理案例
    ansible基本操作
    MySQL改密
    mysql源码包安装
    ftp搭建mysql服务器
  • 原文地址:https://www.cnblogs.com/dracohan/p/4179475.html
Copyright © 2020-2023  润新知