GESP 六级 · GESP 202509 C++ 六级 第 3 题

选择题 · 答案 C · 考点:函数

← 整套速查表 GESP 六级 全部真题

题目

下面代码中 v1 和 v2 调用了相同接口 move(),但输出结果不同。这体现了面向对象编程的( )特性。

class Vehicle {
private:
    string brand;

public:
    Vehicle(string b) : brand(b) {}

    void setBrand(const string& b) { brand = b; }
    string getBrand() const { return brand; }

    virtual void move() const {
        cout << brand << " is moving..." << endl;
    }
};

class Car : public Vehicle {
private:
    int seatCount;

public:
    Car(string b, int seats) : Vehicle(b), seatCount(seats) {}

    void showInfo() const {
        cout << "This car is a " << getBrand()
             << " with " << seatCount << " seats." << endl;
    }

    void move() const override {
        cout << getBrand() << " car is driving on the road!" << endl;
    }
};

class Bike : public Vehicle {
public:
    Bike(string b) : Vehicle(b) {}

    void move() const override {
        cout << getBrand() << " bike is cycling on the path!" << endl;
    }
};

int main() {
    Vehicle* v1 = new Car("Toyota", 5);
    Vehicle* v2 = new Bike("Giant");

    v1->move();
    v2->move();

    delete v1;
    delete v2;
    return 0;
}
答案:C

考点

函数

解题思维

分析时间复杂度时关注循环层数和每层迭代次数,递归算法则分析递归树。注意最坏/最好/平均情况的区别。

常见错误

分析复杂度时注意外层循环和内层循环的关联。例如内外两层都到n的循环不一定是O(n²),要看内层是否每次都在缩小。

详细解析(节选)

【考点】虚函数|多态|对象切片

1. 🎯 考纲定位

GESP 六级核心考点:虚函数与多态。命题人故意用基类指针调用派生类方法,专卡学生混淆“继承”与“多态”——前者是类型关系,后者才是运行时行为差异。

同考点真题

在 OI伴学 里做这道题
登录后可计时作答、查看完整六段式解析,并按你的错题自动生成同类练习。
去刷题先做一次 AI 学情诊断