为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

蝴蝶刀刀 2018-12-04 15:16:25
抽象类不能实例化,但是请看下面这个程序,为什么可以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();    }    }
查看完整描述

2 回答

?
动漫人物

TA贡献1815条经验 获得超10个赞

亲,这是实例化了一个WindowAdapter的内部类,而内部类是该类的一个子类。这样当然可以实例化了。

查看完整回答
反对 回复 2018-12-08
  • 2 回答
  • 0 关注
  • 704 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信