问题
单项选择题
下列程序的输出结果是( )。 classA{ int i,j; A(int i,int j) { this.i=i; this.j=j; } void print( ) { System.out.println("i="+i+""+"j="+j) } class B extends A{ int in; B (int i,int j,int m){ super(a,B) ; this.m=m; } void print( ) { Sytem.out.println("m+"+m);} } class C { public static void main (strang argsⅡ) { B b:new B(1,2,3); b.print( ); } }
A. i=1 j=2 m=3
B. m=3
C. i=3 j=2
D. m=1 i=1
答案
参考答案:B
解析:在对象b调用prin()方法时,使用了类B内定义的print()版本,即在类B内的print()版本覆盖了在类A中的print()方法。