度小满校园招聘笔试题

综合知识 · 历年真题改编 · 题号 42043
单选题综合知识难度 3真题改编 · 2023中大厂

题目

下面代码执行后的输出结果为? #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; }

选项4 个

A1 2 1 4 1 4
B1 2 1 4 3 4
C1 2 1 2 3 2
D1 2 3 4 3 4
🔒 答案与解析:登录后可查看本题答案、解析与考点讲解,并可在线作答自动判分 登录 / 注册
‹ 上一题 全部专题 下一题 ›

同类型题目综合知识 · 继续练习

题目免费浏览 · 整套练习与模拟考登录后开始 · 答案与解析登录后可见