In c++: What is the difference between public and private inheritance?
As far as I know that public and private inheritance does not dictate what is inherited but how it is inherited? So if I have these choice would it be true if I say the correct answer is: d) but the answer for c) seem true too?
(a) Publicly derived classes inherit only the public data members, whereas privately
derived classes inherit only the private data members
(b) Publicly derived classes inherit both the public and private data members, whereas
privately derived classes inherit only the private data members
(c) Public inheritance makes the public members of the base class public in the derived
class; private inheritance makes public base class members private in the derived
class
(d) Private inheritance changes the default accessibility for new members of a derived
class to private: whereas public inheritance leaves the default for new members as
public:
(e) Public inheritance represents an "is implemented as" relationship, whereas private
inheritance represents an "is a" relationship
Can anyone clarify me on these. Thanks.
(a) Publicly derived classes inherit only the public data members, whereas privately
derived classes inherit only the private data members
(b) Publicly derived classes inherit both the public and private data members, whereas
privately derived classes inherit only the private data members
(c) Public inheritance makes the public members of the base class public in the derived
class; private inheritance makes public base class members private in the derived
class
(d) Private inheritance changes the default accessibility for new members of a derived
class to private: whereas public inheritance leaves the default for new members as
public:
(e) Public inheritance represents an "is implemented as" relationship, whereas private
inheritance represents an "is a" relationship
Can anyone clarify me on these. Thanks.
VulpesPosted Jan 23, 2012, 3:50 PM
siabanie baniePosted Jan 23, 2012, 3:17 PM
Is it:
1. Belongs to a particular class, but (in some ways) acts like is doesn't Or
2. Doesn't belong to a particular class, but (in some ways) acts like it does. Or
3. Belongs to a particular class, but can be called without referring to an object of that class.
For me I would answer no. 2 - is that correct?
siabanie baniePosted Jan 23, 2012, 3:08 PM
VulpesPosted Jan 23, 2012, 2:12 PM
Abstraction of functionality is represented by functions which may or may not be members of classes.
I'd say the best answer is (b) - a mechanism for abstraction of structure - though the usual term used is 'data abstraction'.
siabanie baniePosted Jan 23, 2012, 2:02 PM
(a) Classes are the C++ mechanism for abstraction of functionality
(b) Classes are the C++ mechanism for abstraction of structure
(c) Classes are the C++ mechanism for abstraction of functionality and structure
(d) Classes are an alternative to abstraction.
(e) Classes are an encapsulation mechanism and not related to abstraction at all.
I have read online and it seems to me that it is pointing to the choice e) but it also sound b)
Much appreciated.
VulpesPosted Jan 23, 2012, 1:48 PM