Question
The following C++ code has a common inheritance-related issue. How can it be debugged to ensure the derived class constructor properly initializes the base class? #include #include class Person { public: std::string name; Person(std::string
The following C++ code has a common inheritance-related issue. How can it be debugged to ensure the derived class constructor properly initializes the base class? #include #include class Person { public: std::string name; Person(std::string
n) : name(n) {} }; class Student : public Person { public: int studentId; Student(std::string n, int id) { // Problematic: Base class not initialized studentId = id; } void display() { std::cout << "Name: " << name << ", ID: " << studentId << std::endl; } }; int main() { Student s("Alice", 101); s.display(); return 0; }
More IT Operating System Questions
- Which of the following best describes a gateway in Computer Networks?
- Three processes P1, P2 and P3 arrive at time 0 (in that order) with burst times 10, 5 and 8 ms. Using Round Robin with a time quantum of 4 ms, what is the ...
- Which of the following is a default connector for Shielded twisted pair?
- What does the acronym "REST," commonly used in the context of web APIs, stand for, and what is one of its defining characteristics?
- Consider the following Java code: import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexGroup { public static void ...
- What is overfitting in the context of machine learning models?
- Which of the following sorting algorithms has the best worst-case time complexity of O(n log n)?
- In a demand-paged system, the memory access time is 200 ns and the average page-fault service time is 8 ms. For the effective access time not to exceed 400...
- 'Thrashing' in a virtual memory system refers to a condition where:
- What is the primary goal of code optimization in software development?
Hey! Ask a query
Please enter email id
The email must be a valid email address.
Please enter Mobile Number
Please enter valid Mobile Number
Please enter your Doubt
Think You're Ready for RBI Grade B?
RBI Grade B 2026 Phase 1 Memory Based Paper
- 200 Questions with Detailed Solutions
- Section-wise Coverage (GA, English, Quant & Reasoning)