}
}
super.test();
System.out.print(\
A、产生编译错误 B、代码可以编译运行,并输出结果AB C、代码可以编译运行,但没有输出 D、编译没有错误,但会产生运行时异常
四、分析题
阅读下面的程序,分析代码是否能编译通过,如果能编译通过,请列出运行的结果。如果不能编译通过,请说明原因。 代码一:进入catch代码块
进入finally代码块(程序编译能通过,这是因为int x = 2 / 0; System.out.println(x);这两条语句使用了try块,捕获了程序因为除以0而产生的异常情况,之后程序会继续向下执行,输出“进入catch代码块”,“进入finally代码块”。)
public class Test01 {
public static void main(String[] args) { }
try {
int x = 2 / 0;
System.out.println(x);
} catch (Exception e) { }
System.out.println(\进入catch代码块\System.out.println(\进入finally代码块\} finally {
}
代码二:不能,final修饰shout,不能被重写(程序编译不通过,这是因为在程序中使用了final关键字修饰Animal类,使得Animal类不能被继承。shout()方法中同样使用了final关键字,使得该方法不能被重写。)
final class Animal { }
class Dog extends Animal {
public final void shout() { }
// 程序代码
}
public void shout() { }
// 程序代码
class Test02 { }
public static void main(String[] args) { }
Dog dog=new Dog();
代码三:动物叫!
汪汪……
class Animal { }
class Dog extends Animal { }
public class Test03 { }
public static void main(String[] args) { }
Animal animal = new Dog(); animal.shout();
void shout() { }
super.shout();
System.out.println(\汪汪……\void shout() { }
System.out.println(\动物叫!\
代码四:不能,Dog没有实现Animal所有方法,Dog为抽象类不能创建对象(程序编译不通过,因为接
口中定义的方法不能有方法体,所以定义的eat()方法是错误的。接口中的方法必须在子类中全部实现,由于run()方法在子类中并没有重新实现,所以这也是错误的。)
interface Animal { }
class Dog implements Animal {
public void breathe() { void breathe(); void run(); void eat(){};
System.out.println(\’m breathing\} </