答案a我看不懂, 其它答案都错,所有我选a。 静态方法可以被重载 私有方法也可以被重载 符合d的是重写 (override)而不是重载(overload) An overrided method cannot throw exceptions not checked in the base class.才是对的。
d肯定是错的: import java.io.*; class A { int a; public A() { a=10; } public void print() { System.out.println("aaa"); } };class B extends A { public B() { a=20; } public void print(int c) throws IOException{ System.out.println("bbbb"); } };public class test2 { static void main(String args[]) { B b = new B(); A a = new A(); a.print(); b.print(); } } 上面的程序编译和运行没有任何问题!
其它答案都错,所有我选a。
静态方法可以被重载
私有方法也可以被重载
符合d的是重写 (override)而不是重载(overload)
An overrided method cannot throw exceptions not checked in the base class.才是对的。
import java.io.*;
class A {
int a;
public A() {
a=10;
}
public void print() {
System.out.println("aaa");
}
};class B extends A {
public B() {
a=20;
}
public void print(int c) throws IOException{
System.out.println("bbbb");
}
};public class test2 {
static void main(String args[])
{
B b = new B();
A a = new A();
a.print();
b.print();
}
}
上面的程序编译和运行没有任何问题!
D是错的。重载可以throws exception(在base class没有的),覆盖则不能。
A肯定是对的。方法不可能被覆盖成更private.
(编译之后好象会改名字的)