Question
Download Solution PDFIdentify the error in the following code :
1 class exam
2 { public :
3 virtual void show () = 0;
4 };
5 int main (void)
6 {exam e;
7 exam * ep ;
8 return 0 ; }
Answer (Detailed Solution Below)
Detailed Solution
Download Solution PDFThe correct answer is: option 2: compiler error at line 6
Concept:
The class exam
contains a pure virtual function (virtual void show() = 0;
), which makes exam
an abstract class.
In C++, you cannot create an object of an abstract class. Attempting to do so results in a compiler error.
Explanation of code lines:
- Line 6:
exam e;
❌ ❗ This causes a **compiler error** because you cannot instantiate an object of an abstract class. - Line 7:
exam *ep;
✅ This is valid. You can create a pointer to an abstract class.
Explanation of options:
- Option 1 – compiler error at line 6 and 7: ❌ Incorrect. Line 7 is valid.
- Option 2 – compiler error at line 6: ✅ Correct.
- Option 3 – compiler error at line 7: ❌ Incorrect. Line 7 is legal.
- Option 4 – compiler error at 2, 4 and 6: ❌ Lines 2 and 4 are syntactically and semantically valid.
Hence, the correct answer is: option 2: compiler error at line 6
Last updated on Jul 3, 2025
-> NIELIT Scientific Assistant answer key 2025 has been released at the official website.
-> NIELIT Scientific Assistant admit card 2025 has been released.
-> NIELIT Scientific Assistant city intimation slip 2025 has been released at the official website.
-> NIELIT Scientific Assistant exam 2025 is scheduled to be conducted on June 28.
-> A total number of 113 revised vacancies have been announced for the post of Scientific Assistant in Computer Science (CS), Information Technology (IT), and Electronics & Communication (EC) streams.
-> Online application form, last date has been extended up to from 17th April 2025.
->The NIELT has revised the Essential Qualifications for the post of Scientific Assistant. Candidates must possess (M.Sc.)/ (MS)/ (MCA) / (B.E.)/ (B.Tech) in relevant disciplines.
-> The NIELIT Scientific Assistant 2025 Notification has been released by the National Institute of Electronics and Information Technology (NIELIT).