java中抽象类不能实例化的问题

抽象类不能实例化,但是请看下面这个程序,为什么可以new WindowAdapter()?

class FrameTest4 {

    public static void main(String[] args){

        new NewFrame("窗口");

    }

}

class NewFrame extends Frame{

    TextArea text;

    NewFrame(String s){

        super(s);

        setBounds(100,100,200,300);

        setVisible(true);

        text=new TextArea();add(text,BorderLayout.CENTER);

        addWindowListener(new WindowAdapter(){

            public void windowActivated(WindowEvent e){

                text.append("\n我被激活");

            }

            public void windowClosing(WindowEvent e){

                System.exit(0);

            }

        });

        validate();

    }

    

}


蝴蝶刀刀
浏览 705回答 2
2回答

动漫人物

亲,这是实例化了一个WindowAdapter的内部类,而内部类是该类的一个子类。这样当然可以实例化了。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java