Multiple choice

What will be the output of the following program?#include<iostream.h> class sun { public: void result() { cout<< class sun ; } }; class moon { public: void result() { cout<< class moon ; } }; class stars:public sun,public moon { public: void show() { cout<< class stars ; } }; void main() { stars s; s.result(); }

  1. class stars

  2. class moon

  3. class sun

  4. none of the above

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

This code has a compilation error due to diamond inheritance ambiguity. Class stars inherits from both sun and moon, each having a result() method. Calling s.result() is ambiguous - the compiler cannot determine which result() to use. This requires scope resolution (s.sun::result() or s.moon::result()) or virtual inheritance.