内部类
package singleModel; import java.awt.Button; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class OuterClass { public static void main(String[] args) { } //1.对同包下的其他类隐藏 //2.可以访问内部类定义作用域的属性,包括所有属性 //3.匿名内部类回调函数,简化代码 /* class innerClass{ //外部内访问属性 // private String field="field"; public String field="field"; }*/ /* private String outer = "outer"; class InnerClass{ public void test(){ System.out.println("test"); String s = OuterClass.this.outer; } }*/ //匿名内部类,不需要命名,直接声明一个对象到参数 /* private Button button = null; public OuterClass(){ button = new Button(); //参数new对象,不用声明,匿名 button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println( e.getActionCommand() ); } }); } private ActionListener actionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println( e.getActionCommand() ); } };*/ }