public class InnerTest {
public static void main(String[] args) {
Parsent p=new Parsent(){
public void show(){
System.out.println("匿名内部类!!!");
}
};
Inne i=(Inne)p;
i.show();
}
}
(代码中Inne继承Parsent类。)
报错:Exception in thread "main" java.lang.ClassCastException: Test.Inner$1 cannot be cast to Test.Inne
at Test.Inner.main(Inner.java:11)
...全文
2367打赏收藏
将匿名内部类创建父类对象 然后再强转为其子类 报错。。
package Test; public class InnerTest { public static void main(String[] args) { Parsent p=new Parsent(){ public void show(){ System.out.println("匿名内部类!!!"); } }; Inne i=(Inne)p; i.show(); } } (代码中Inne继承Parsent类。) 报错:Exception in thread "main" java.l