下述哪一组方法,是一个类中方法重载的正确写法?( )
A. int addValue( int a, int b ){return a+b;}float addValue ( float a, float b) {return a+b;}
B. int addValue (int a, int b ){value=a+b; }float addValue ( int a, int b) {return (float)(a+b);}
C. int addValue( int a, int b ){return a+1;}int addValue ( int a, int b) {return a+b;}
D. int addValue( int a, int b ) {return a+b;}int addValue ( int x, int y ) {return x+y;}
查看答案
阅读以下程序:classAA{doublex=1.1;doublemethod(){returnx;}}classBBextendsAA{doublex=2.2;doublemethod(){returnx;}publicstaticvoidmain(Stringargs[]){AAa=newBB();System.out.println(a.x);}}程序的输出结果是:()
A. 1.1
B. 2.2
C. 0
D. 编译出错
阅读以下程序代码:classAA{doublex=1.1;doublemethod(){returnx;}}classBBextendsAA{doublex=2.2;doublemethod(){returnx;}publicstaticvoidmain(Stringargs[]){AAa=newBB();System.out.println(a.method());}}程序的输出结果是()。
A. 1.1
B. 2.2
C. 0
D. 编译出错
使用下列哪个关键字,可以判断一个变量的具体类型()?
A. as
B. is
C. instanceof
D. extends
运用所学有关“多态”的编程知识,分析程序:public class Pencil {public void write(String content) {System.out.println("Write" + content);}public static void main(String[] args) {Pencil pen=new Pencil();(( RubberPencil) pen).write( "Hello");}}class RubberPencil extends Pencil {public void write(String content) {System.out.println("Rubber Write" + content);}public void erase(String content) {System.out.println("Erase " + content);}}执行以上程序代码的结果是()?
A. Write Hello
B. Rubber Write Hello
C. 运行时抛出异常
D. 编译失败