---
title: "单例模式之饿汉模式"
author: "bigSeven"
date: "2015-12-05T17:02:40Z"
tags: ["Java设计模式", "单例模式", "饿汉模式"]
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2015-12-05T17:02:40Z"
id: 2262041
url: "https://bigseven.iteye.com/blog/2262041"
---

package mode;

 

/\**

 * 单例模式之饿汉模式

 * @author gaoq

 * @date 2015-12-5 下午4:50:13

 \*/

public class SingletonMode {

 

private static final SingletonMode singletonMode = new SingletonMode();

 

private SingletonMode(){

 

}

 

public static SingletonMode getInstance(){

return singletonMode;

}

 

public void test(){

System.out.println("你好，饿汉");

}

 

}

============================================

package mode;

/\**

 * 测试类

 * @author gaoq

 * @date 2015-12-5 下午4:54:50

 \*/

public class TestMain {

 

public static void main(String\[] args) {

SingletonMode.getInstance().test();

}

 

}