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 {};
Discussion:
30 comments Page 1 of 3.
Amit said:
1 decade ago
The above program compile successfully. Because in this program a class is defined in another class with protected specifier.
(1)
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.
But here there will be no output because there are no methods or variables in both the class.
(1)
Akshay said:
9 years ago
Their is no output because their is no use of constructor and destructor but program compile successfully.
(1)
Eknath said:
1 decade ago
It will compile successfully. We can have a empty class and can inherit protected from any class. Nothing will be displayed on console as we are not writing anything to console.
Shashi said:
1 decade ago
There is no error in this program. It does not matter whether the body is defined or not. It will compile successfully.
Anirban Sanyal said:
1 decade ago
Ya it will compile because class can be protected inherited from other class.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers