• This关键字,打印花瓣的数量


    /**
     * 测试构造器类
     * 打印花瓣数量
     * <p>
     * 很喜欢《Thing in java》5.4章中关于this关键字的这个小例子
     * 写下来仅表纪念和喜欢
     * </P>
     * @author zhangss 2017-3-27 17:12:10
     * @version 1.0
     * */
    public class Flower {
        int petalCount = 0;
        String s = "initial value";
        
        Flower(int petals){
            petalCount = petals;
            System.out.println("Constructor w/ int arg only, petalCount = "  + petalCount);
        }
        
        Flower(String ss){
            System.out.println("Constructor w/ int arg only, s = "  + ss);
        }
        
        Flower(String s, int petals){
            this(petals);
    //        this(petals);// can't call two!
            this.s = s;
            System.out.println("String & int args");
        }
        
        Flower(){
            this("hi", 47);
            System.out.println("default constructor (no args)");
        }
        void printPetalCount(){
    //        this(11); // not inside non-constructor
            System.out.println("petalCount = " + petalCount + " s " + s);
        }
        public static void main(String[] args){
            Flower f = new Flower();
            f.printPetalCount();
        }
    }
  • 相关阅读:
    SDN组网相关解决方案
    Linux C中结构体初始化
    lambda函数、lambda表达式
    流量工程 traffic engineering (TE)
    BGP路由协议详解(完整篇)
    Overlay network 覆盖网络
    覆盖路由
    重叠(Overlapping) NAT
    Multiprotocol Label Switching (MPLS)
    MPLS
  • 原文地址:https://www.cnblogs.com/zsslll/p/6627773.html
Copyright © 2020-2023  润新知