java算法面试题:写一个Singleton出来

package com.swift;public class Singleton {    public static void main(String[] args) {        /*         * 写一个Singleton出来         */        ORC_Hungry.getOrc().fun();        ORC_Lazy.getOrc().fun();    }}class ORC_Hungry{    //饿汉式    private static ORC_Hungry orc=new ORC_Hungry();    private ORC_Hungry() {}    public static ORC_Hungry getOrc() {        return orc;    }    public void fun() {        System.out.println("This is a hungry Singleton.....");    }}class ORC_Lazy{    //懒汉式    private static ORC_Lazy orc;    private ORC_Lazy() {}    public static synchronized ORC_Lazy getOrc() {        if(orc==null) {            orc=new ORC_Lazy();        }        return orc;    }    public void fun() {        System.out.println("This is a lazy Singleton.....");    }}

不畏不惧,不言不弃,冲破风雨的阻隔,黎明就在前方!

java算法面试题:写一个Singleton出来

相关文章:

你感兴趣的文章:

标签云: