C++ Programming - Objects and Classes - Discussion

Discussion Forum : Objects and Classes - General Questions (Q.No. 1)
1.
What happens when we try to compile the class definition in following code snippet?
class Birds {};
class Peacock : protected Birds {};
It will not compile because class body of Birds is not defined.
It will not compile because class body of Peacock is not defined.
It will not compile because a class cannot be protectedly inherited from other class.
It will compile succesfully.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
30 comments Page 1 of 3.

Anuja said:   6 years ago
It'll compile as protected access specified provides inheritance or data member functions accessibility only to the next immediate derived class.
(1)

Raees said:   8 years ago
Yeah, it will compile.
(1)

Bhn said:   8 years ago
Class can be protected & inherited from other class.
(1)

Ramkishore Gautam said:   8 years ago
It will not compile successfully without main ().
(1)

Utkarsh Rai said:   8 years ago
It Can be compiled successfully because as the protected (access specifier) helps peacock class only (child class) to get accessthrough the methods and variables of birds class (parent class).

But here there will be no output because there are no methods or variables in both the class.
(1)

Naveen said:   9 years ago
There is no output but it compiled sucessfully.

Xxx said:   9 years ago
Agree with you @Akshay. So confused to choose the answer.

Akshay said:   9 years ago
Their is no output because their is no use of constructor and destructor but program compile successfully.
(1)

PRABAVATHY said:   10 years ago
Ya it will inherited when we inherit using public and protected.

Sann said:   10 years ago
What situation we should inherit protected or private if class is public?


Post your comments here:

Your comments will be displayed after verification.