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.
Pankaj sharma said:
1 decade ago
It will compile successfully but will not execute as main is the very first function to be called and it is called every time by say a master program running somewhere behind and from there the further references are given by us to do whatever required acc to need.
So it will only compile not execute.
So it will only compile not execute.
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)
C++ said:
1 decade ago
This particular code "snippet" does not have any errors. THUS option D is correct. Of Course to run you will need a main function.
The : is not scope resolution operators. That is how classes are inherited in C++.
The : is not scope resolution operators. That is how classes are inherited in C++.
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.
Suman said:
1 decade ago
The code will compile properly. Since the existence of class is only by object of that particular class and there are know syntax error in the code.
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)
Ashwinrpai said:
1 decade ago
We can read the above statement as "peacock is a a bird". Class peacock is a class which inherits from class bird, in a protected manner.
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)
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.
Akshay said:
9 years ago
Their is no output because their is no use of constructor and destructor but program compile successfully.
(1)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers