If all required header files are already included, identify the output of the…
2023
If all required header files are already included, identify the output of the following C++ code from the given options:
class Student { int AdmNo, Class; public: Student (int AN, int C = 1) { AdmNo = AN; Class = C; }
void Promoted (int C = 1) { Class += C; }
void Display () { cout << AdmNo << " : " << Class << endl; } };
void main () { Student S (1001); S.Promoted (3); S.Display (); }
Answer: B. 1001 : 4 — The object S is created with Student S(1001); , so AdmNo = 1001 and default Class = 1 . Then S.Promoted(3) adds 3 to Class , making it 1 + 3 = 4 . Hence the…
- A.
1001 : 1
- B.
1001 : 4
- C.
1001 : 3
- D.
1001 : 2
Attempted by 262 students.
Show answer & explanation
Correct answer: B
The object S is created with Student S(1001); , so AdmNo = 1001 and default Class = 1 . Then S.Promoted(3) adds 3 to Class , making it 1 + 3 = 4 . Hence the output is 1001 : 4.