当前位置: 技术问答>java相关
都说抽象类不能实例化,可是请看下面例子:(请大虾们解释)
来源: 互联网 发布时间:2015-02-28
本文导语: addMouseListener(new java.awt.event.MouseAdapter(){ public void mouseClicked(MouseEvent e){ onMouseClicked(e); } }); public void onMouseClicked(MouseEvent e) ...
addMouseListener(new java.awt.event.MouseAdapter(){
public void mouseClicked(MouseEvent e){
onMouseClicked(e);
}
});
public void onMouseClicked(MouseEvent e)
{
}
MouseAdapter可是abstract类呀,不信可以查jdk文档,为什么可以new MouseAdaper()呢????
public void mouseClicked(MouseEvent e){
onMouseClicked(e);
}
});
public void onMouseClicked(MouseEvent e)
{
}
MouseAdapter可是abstract类呀,不信可以查jdk文档,为什么可以new MouseAdaper()呢????
|
抽象类是不能直接实例的,这个例子实际是对内部类的实例,这个幂名内部类继承了MouseAdapter
|
Asprilla说的对,你没搞懂匿名内部类的含义