1.

If the protected members are to be made accessible only to the nearest subclass and no further subclasses, which access specifier should be used in inheritance?(a) The sub class should inherit the parent class privately(b) The sub class should inherit the parent class as protected(c) The sub class should inherit the parent class as public(d) The sub class can use any access modifierThe question was posed to me in an interview for job.Origin of the question is Protected Access Specifier in chapter Access Specifiers of Object Oriented Programming

Answer»

The CORRECT choice is (a) The sub class should INHERIT the parent class privately

To EXPLAIN I would say: The sub class should USE private inheritance. This will allow only the nearest sub classes to inherit the protected members and then those members will BECOME private. Hence further inheritance of those members will not be possible.



Discussion

No Comment Found

Related InterviewSolutions