COMPILER DESIGN

ADVANCED TOPICS IN COMPILER DESIGN

CODE GENERATION FOR OBJECT ORIENTED LANGUAGES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
When deriving from a private base class, the public, protected and private members of the base class become private members of the derived class.
A
True
B
False
C
Either A or B
D
None of the above
Explanation: 

Detailed explanation-1: -Protected Inheritance − When deriving from a protected base class, public and protected members of the base class become protected members of the derived class. Private Inheritance − When deriving from a private base class, public and protected members of the base class become private members of the derived class.

Detailed explanation-2: -With private inheritance, public and protected member of the base class become private members of the derived class. That means the methods of the base class do not become the public interface of the derived object. However, they can be used inside the member functions of the derived class.

Detailed explanation-3: -protected inheritance-the public and protected members of the base class are inherited as protected members of the derived class. The private members are NOT accessible by the derived class. private inheritance-the public and protected members of the base class are inherited as private members of the derived class.

Detailed explanation-4: -A derived class cannot access protected members of its base class through an instance of the base class. An instance of the base class declared in the derived class might, at run time, be an instance of another type that is derived from the same base but is not otherwise related to the derived class.

Detailed explanation-5: -The technical answer is yes, the derived class inherits all the fields and methods of the base class. But any that were marked private stay private. Using protected as the access specifier means the method or field is: Accessible to subclasses.

There is 1 question to complete.