内部类的使用

package com.gxnu.edu.lqm.collection;

public class NestEx {
private String name;

public class Nest{
public void Nest(String str){
System.out.println(str);
}
}

public static class StaticNest{
public void play(){
System.out.println("play");
}
}

public NestEx() {
super();
// TODO Auto-generated constructor stub
}

public NestEx(String name) {
super();
this.name = name;
}

@Override
public String toString() {
return "NestEx [name=" + name + "]";
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}

 

 

 

package com.gxnu.edu.lqm.collection.test;

import org.junit.Test;

import com.gxnu.edu.lqm.collection.NestEx;
import com.gxnu.edu.lqm.collection.NestEx.Nest;
import com.gxnu.edu.lqm.collection.NestEx.StaticNest;

public class NestTest {
@Test
public void testNest(){
NestEx nestEx = new NestEx();
NestEx.Nest nest = nestEx.new Nest();
nest.Nest("xxioa");
NestEx.StaticNest staticNest = new NestEx.StaticNest();
staticNest.play();
}

@Test
public void testNest1(){
NestEx nestEx = new NestEx();
Nest nest = nestEx.new Nest();
nest.Nest("xxioa");
StaticNest staticNest = new NestEx.StaticNest();
staticNest.play();
}
}

posted @ 2018-07-19 19:21  智敏罗  阅读(1000)  评论(0编辑  收藏  举报