---
title: "static 非static运行次数 "
author: "east_java"
date: "2009-07-29T09:47:53Z"
tags: []
slug: "static-static"
draft: false
lastmod: "2009-07-29T20:25:46Z"
id: 435031
url: "https://japi.iteye.com/blog/435031"
---

```java
public class StaticM {
	public static Integer i;
	public  MM a = new MM();
	static {
		i = 10;
		System.out.println("sss");
		i--;
	}
	public static void pp(){
		new StaticM().new MM().p();
	}
	
	class MM{
		public MM(){
			i--;
			System.out.println("mm"+i);
		}
		public void p(){
			System.out.println("ppp");
		}
	}
}
```


上面的代码 在运行时候 创建了几个实例，MM类就也得创建几个实例。
而static块中的代码只运行一次。仅仅一次！