问题 单项选择题

下列程序的输出结果是( )。  class Father{  int m.n;  Father(int a,int B)   { m=a;   n=b  }  void show ( ){  System.out.println("m and n:"+m+" "+n);  }  }  class Son extends Father{  int p;  Son (int a,int b,int C)   { super(a,B) ;   p=c;  }  void show(){supur.show( );  System.out.println("p:"+p);  }  }  class Test {  public static void main (String args[ ])  { Son s:new Son(6,7,8);    s.show( );  }  }

A. True

B. False

C.-1

D.1

答案

参考答案:B

解析:本题考查的是For循环结构语句,程序段的运行过程为:开始a=1,b=2。For循环中步长缺省值为1,循环变量I的初值为1,终值为3,所以此循环结构可以循环3次。  第一次循环后,结果为:f=2,a=2,b=2;  第二次循环后,结果为:f=4,a=2,b=4;  第三次循环后,结果为:f=8,a=4,b=8;  所以每循环一次,便输出f当前值,循环3次即便输出3个f值分别为2,4,8。

填空题
选择题