内部类的使用
Posted jiminluo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了内部类的使用相关的知识,希望对你有一定的参考价值。
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();
}
}
以上是关于内部类的使用的主要内容,如果未能解决你的问题,请参考以下文章