Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

if you have class GradStudent : public Student what can the class GradStudent ac

ID: 3733979 • Letter: I

Question

if you have class GradStudent : public Student what can the class GradStudent access within the class Student? ii. What can a client of GradStudent access within the class Student? b) If later you had class DoctoralStudent public GradStudent i. What can the class DoctoralStudent access within the class Student? ii. What can a client of DoctoralStudent access within the class Student? c) How would your answers to a) change if inheritance was protected ? d) How would your answers to b) change if inheritance was protected? e) How would your answers to a) change if inheritance was private ? f) How would your answers to b) change if inheritance was private?

Explanation / Answer

a)

i) The class GradStudent can access all the public and protected data members and member functions of the class Student.

Reason: the access specifier used to inherit class Student is 'public'

ii) The client of GradStudent can also access all the public and protected data member and public member functions of the class Student.

Reason: The 'public' access specifier allows other classes that inherit the class publicaly to access all the public and protected data members and member functions.

b)

i) The class DoctoralStudent can access all the public and protected data members and member functions of the class Student.

Reason: Since DoctoralStudent is inheriting the class GradStudent publically, you should note that the class GradStudent has previously inherited the class Student publically as well. So all the public and protected data members and member functions of the class Student is available to the client of the class GradStudent as well, or in this case: class DOctoralStudent

ii) The client of DoctoralStudent can also access all the public and protected data members and member functions of the class Student, since this property of public inheritence is continous in the levels. So its the same reason as reason for a) ii).

c) If the inheritance is protected, then

i) GradStudent can access the protected and the public data members and the member functions of the class Student.

Reason: the access specifier used to inherit class Student will be protected.

ii) The client of the class GradStudent will be able to access only the public data members and member functions of the class Student.

Reason: The protected access specifier, makes the protected data members and member functions of the inherited class as private. Hence the client of the derived class cant access them.

d) If the inheritance is protected, then

i) DoctoralStudent can only access the public data members and member functions of the class Student.

Reason: Same as c) ii)

ii) DoctoralStudent class's clients can only access the public data members and member functions of the class Student

Reason: Same as c) ii)

e) If the inheritance is private, then

i) The class GradStudent can only access the public data members and member functions of the class Student

Reason: The access sspecifier used here is private

ii) The client of class GradStudent can not access any data member or member functions of the class Student.

Reason: The public members become private upon inheritance by private access specifier.

f) If the inheritance is private, then

i) The class DoctoralStudent won't be able to inherit any data member or member functions of the class Student

Reason: All the members of the class Student become private in class GradStudent, so there is no member of class Student that the class Doctoral Student can access.

ii) The client of class DoctoralStudent won't be able to inherit any data member or member functions of the class Student

Reason: Same as e) ii) and f) i)