题库 软件开发 题目列表 下面代码执行后的输出结果为? #include <ios...
单选题
下面代码执行后的输出结果为?
#include <iostream>
using namespace std;
class Animal {
public:
    void eat() {
        cout << "1" << endl;
    }
    virtual void drink() {
        cout << "2" << endl;
    }
};
class Dog : public Animal {
public:
    void eat() {
        cout << "3" << endl;
    }
    void drink() {
        cout << "4" << endl;
    }
};
int main() {
    Animal ani;
    Dog dog;
    Animal *p = &ani;
    p->eat();
    p->drink();
    p = &dog;
    p->eat();
    p->drink();
    Animal *ptr = (Animal*)&dog;
    ptr->eat();
    ptr->drink();
    return 0;
}

A.

1 2 1 4 1 4

B.

1 2 1 4 3 4

C.

1 2 1 2 3 2

D.

1 2 3 4 3 4

题目信息
校招真题
-
正确率
0
评论
9
点击