第38920题 单选题
下列代码中,d1->work(); 和 d2->work(); 输出不同结果的主要原因是( )。
class Device {
public:
    virtual void work() {
        cout << "Device is working" << endl;
    }
    virtual ~Device() {}
};

class Printer : public Device {
public:
    void work() override {
        cout << "Printer is printing" << endl;
    }
};

class Scanner : public Device {
public:
    void work() override {
        cout << "Scanner is scanning" << endl;
    }
};

int main() {
    Device* d1 = new Printer();
    Device* d2 = new Scanner();

    d1->work();
    d2->work();

    delete d1;
    delete d2;
    return 0;
}
/ 12
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
知识点:
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析