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 2 of 3.
Nirbhay singh said:
10 years ago
This program is correct but no output. Because no constructor and destructor are use.
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.
Debasmita Manna said:
1 decade ago
I do think that option d is correct because compiler is already mention bird as a class.
Kirti said:
1 decade ago
In the above program peacock is a class which protected inherits the class bird.
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)
Bhuvnesh kumar said:
1 decade ago
It is will compile properly because peacock is class which protected inherits the class bird.
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.
Srijeth said:
1 decade ago
What does class peacock:protected birds{}; mean?
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++.
Sumasree said:
1 decade ago
Without main method it's shows like this message -undefined reference to 'main'.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers