选项中哪一行代码可以添加 题目中而不产生编译错误? public abstract class MyClass { public int constInt = 5; //add code here public void method() { } } public abstract void method(int a); constInt = constInt + 5; public int method(); public abstract void anotherMethod() {}
public abstract class MyClass { public int constInt = 5; //add code here public void method() { } }
答案是A
A是抽象方法,抽象类可以包含抽象方法,也可以不包含,虽然A
方法名是method,与题目中的方法同名,但是参数不同,是重载方法
B 在类中不能constInt = constInt + 5; 方法中可以
C 的方法名与题目中的方法名相同,返回值不能作为重载的依据
D 抽象方法没有方法体