---
title: "java 匿名内部类的使用方法"
author: "junjun16818"
date: "2011-06-16T11:42:45Z"
tags: []
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2011-06-16T11:42:45Z"
id: 1094812
url: "https://junjun16818.iteye.com/blog/1094812"
---

```
public interface Contents {

	public void star();
	
}



public class Goods {
	public Contents cont() {
		return new Contents() {
			private String  i = "heiheihei";

			public String value() {
				return i;
			}

			public void star() {
				// TODO Auto-generated method stub
				System.out.println(value());
			}
		};
	}
}
@Test
	public void test(){

		Goods good = new Goods();
		Contents cont= good.cont();
		cont.star();
		
	}

```