內部類的使用

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

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");
}
}this

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

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

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

public String getName() {
return name;
}class

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

test

}import

 

 

 

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

import org.junit.Test;static

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(); }}

相關文章
相關標籤/搜索