模拟试题一 答案



一、单选题(每题2分,共40分)

1、D   2、C   3、D   4、B   5、C        6、A   7、C   8、A   9、C   10、A

11、D  12、A   13、B  14、C  15、A     16、C   17、C  18、D   19、C  20、B

 

二、简答题(每题5分,共10分)

1、答案:通过必要的说明能够实现某个类无需重新定义就拥有另一个类的某些属性和方法,并把这种关系称为继承,先定义的类称为父类,后定义的类称为子类,并且允许多层的继承关系。

2、答案:重载是指在同一个类中定义了多个名字相同而内容不同的成员方法;覆盖则是指在子类中定义了与父类具有相同名字的成员方法。 

重载与覆盖的区别在于:重载是存在于同一个类的不同方法之间的多态关系,它们主要通过参数表中参数的个数、参数的数据类型和参数的顺序等方面的不同来区分;面覆盖是存在于父类与子类之间的多态关系,它们在引用时通过指出所属类的类名来区分。

 

三、程序结果题(每题5分,共10分)

1、答案:S=180

2、答案 : 课程号:101 课程名:ASP 学分:3

 

四、编程题(共40分)

1、[解答]:

public class Test {

  public static void main(String args[]) {

    double sum = 0.0;

    for (int i = 1;i <= 100;i++ )

      sum += 1.0 / (double) i;

    System.out.println("sum=" + sum);

  }

}

2、 [解答]:

class Test {

  public static void main(String args[]) {

    int a[] = {3, 2, 5, 21, 9, 10, 7, 16, 8, 20};

    int b, c, d;

    System.out.println("befor sorted");

    for (b = 0; b < 10; b++) {

     System.out.print(a + "    ");

    }

    System.out.println("");

    for (b = 1; b <= 9; b++)

     for (c = 0; c <= 9 - b; c++) {

       if (a[c] > a[c + 1]) {

         d = a[c];

         a[c] = a[c + 1];

         a[c + 1] = d;

       }

     }

    System.out.println("after sorted");

    for (b = 0; b < 10; b++) {

      System.out.print(a + "    ");

    }

    System.out.println("");

  }

}

3、[解答]:

public class Rectangle {

  float width,height;

  publicRectangle(float width, float height) {

    this.width = width;

    this.height = height;

  }

  public float getLength() {

    return (this.width + this.height) * 2;

  }

  public float getArea() {

    return this.width * this.height;

  }

  public static void main(String[] args) {

    Rectangle rect = new Rectangle(10, 20);

    System.out.println("周长是:" + rect.getLength());

    System.out.println("面积是:" + rect.getArea());

  }

}