[9급 지방직 컴퓨터일반 2021년 10번]

다음 C++ 프로그램의 실행 결과로 옳은 것은?
#include <iostream>
using namespace std;

class Student {
public:
	Student():Student(0) {};
	Student(int id):_id(id) { 
		if (_id > 0) _cnt++;
	};
	static void print() { cout << _cnt;};
	void printID() { cout << ++_id;};

private:
	int _id;
	static int _cnt;
};

int Student::_cnt = 0;

int main() {
	Student A(2);
	Student B;
	Student C(4);
	Student D(-5);
	Student E;
	Student::print();
	E.printID();
	return 0;
}
컴퓨터일반
  1. ①21
  2. ②22
  3. ③30
  4. ④31

선지를 골라 바로 채점해 보세요.

정답 ①

출처: 인사혁신처 공개 기출(공공데이터포털, 이용허락 제한 없음)

신고가 접수됐습니다. 감사합니다.

오류 신고