Answer to Question #268201 in C++ for Amit

Question #268201

Write a program such that base class pointer or reference will always access/call the derived


version of the members available in derived class, do not have any access to the base class


members.

1
Expert's answer
2021-11-18T15:21:22-0500
#include <iostream>


using namespace std;
class student{
private:
    string name;
    int regno;
 void getData(){
    }
    void diplayData(){
    }
};
class science:private student{
public:
    string name = "meshack";
};
class department:private student{
public:
    string name = "meshack";


};


int main()
{
    student s;
    s.getData();
    s.displayData();
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS