---
title: "java之static变量"
author: "yoyo08"
date: "2010-01-13T20:07:41Z"
tags: []
categories: ["编程语言"]
slug: "java-static"
draft: false
lastmod: "2010-01-13T20:07:41Z"
id: 569545
url: "https://yoyo08.iteye.com/blog/569545"
---

如下面代码：

 

```
public class Test
{
	static int a = 0;
	
	public Test()
	{
		a++;
	}
	
	public static void main(String[] args)
	{
		Test t1 = new Test();
		Test t2 = new Test();

		System.out.println(t1.a);
		System.out.println(t2.a);
		
		System.out.println(a);
		System.out.println(Test.a);
	}
}
```

 

输出为：

```
2
2
2
2
```