zoukankan      html  css  js  c++  java
  • 有关静态模块与对象模块的执行

    package fengke.classtest;
    /**
     *  有关静态模块与对象模块的内容
     * @author 锋客
     *  结果:
     *    不执行对象模块
     *    不调用无参构造方法
     *   总结:static===只要class被加载  就执行,切只执行一次
     *       对象模块只有在使用构造器前才执行,每一次调用构造器,都会执行一次,执行顺序为书写顺序
     *      
     */

    public class Entry {
     private static String inforstatic="static属性生成";
     private int num;
     private String infor;
     static{
      System.out.println("static模块执行了");
     }
     {
      System.out.println("构造器前的对象模块执行!");
     }
     public Entry() {
      super();
      System.out.println("无参的构造器执行!");
     }
     {
      System.out.println("构造器后的对象模块执行!");
     }
     public Entry(int num, String infor) {
      super();
      this.num = num;
      this.infor = infor;
      System.out.println("带参数的构造器执行!");
     }
     @Override
     public String toString() {
      return "Entry [num=" + num + ", infor=" + infor + "]";
     }
     
     public static void main(String[] args) {
      System.out.println("main执行了");
     }

    }

    package fengke.classtest;
    /**
     * 有关静态模块与对象模块的内容
     * @author 锋客
     * Entry entry=null;不会调用Entry这个类
     *
     */
    public class ClassTest {
     public static void main(String[] args) {
      System.out.println("entry1=null的情况下");
      Entry entry1=null;
      System.out.println("entry2=new Entry()的情况下");
      Entry entry2=new Entry(12, "fengke");
      System.out.println("entry3=new Entry()的情况下");
      Entry entry3=new Entry();
     }

    }

  • 相关阅读:
    [Mise] Refetch API data when a state value changes with the `$watch` property in Alpine JS
    Android之用自定义的shape去实现shadow效果
    http抓包以及网速限定
    ios成长之每日一遍(day 7)
    ios成长之每日一遍(day 6)
    ios成长之每日一遍(day 5)
    ios成长之每日一遍(day 4)
    ios成长之每日一遍(day 3)
    ios成长之每日一遍(day 2)
    ios成长之每日一遍(day 1)
  • 原文地址:https://www.cnblogs.com/fengke/p/4916103.html
Copyright © 2011-2022 走看看