62,614
社区成员
发帖
与我相关
我的任务
分享
//就算你这样写也是同样的地方出现异常:
public class Test {
static class A
{
void process() throws Exception
{
throw new Exception();
}
}
static class B extends A
{
void process() throws Exception
{
System.out.println("B ");
}
}
public static void main(String[] args) {
A a=new B();
a.process();
}
}
//解决方法是在a.process()抛出异常,主要因为异常没处理的原因
public class Test {
static class A
{
void process() throws Exception
{
throw new Exception();
}
}
static class B extends A
{
void process()
{
System.out.println("B ");
}
}
public static void main(String[] args) {
A a=new B();
try {
a.process();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class Test
{
static class A
{
void process() throws Exception
{
throw new Exception();
}
}
static class B extends A
{
void process()
{
System.out.println("B ");
}
}
public static void main(String[] args) {
A a=new B();
a.process();
}
}