Question: 7. What will be the output of the following C++ code?<div class="hk1_style-wrap4"><div class="hk1_style-wrap3"><div class="hk1_style-wrap2"><div class="hk1_style-wrap"><div class="hk1_style"><div class="cpp"><ol><li class="li1"><pre class="de1"> <span class="co2">#include &lt;iostream&gt;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw2">using</span> <span class="kw2">namespace</span> std<span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw2">class</span> Base</pre></li><li class="li1"><pre class="de1"> <span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> <span class="kw2">public</span><span class="sy4">:</span></pre></li><li class="li1"><pre class="de1"> <span class="kw2">virtual</span> <span class="kw4">void</span> print<span class="br0">(</span><span class="br0">)</span> <span class="kw4">const</span> <span class="sy1">=</span> <span class="nu0">0</span><span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span><span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw2">class</span> DerivedOne <span class="sy4">:</span> <span class="kw2">virtual</span> <span class="kw2">public</span> Base</pre></li><li class="li1"><pre class="de1"> <span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> <span class="kw2">public</span><span class="sy4">:</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">void</span> print<span class="br0">(</span><span class="br0">)</span> <span class="kw4">const</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">cout</span> <span class="sy1">&lt;&lt;</span> <span class="st0">"1"</span><span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span><span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw2">class</span> DerivedTwo <span class="sy4">:</span> <span class="kw2">virtual</span> <span class="kw2">public</span> Base</pre></li><li class="li1"><pre class="de1"> <span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> <span class="kw2">public</span><span class="sy4">:</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">void</span> print<span class="br0">(</span><span class="br0">)</span> <span class="kw4">const</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">cout</span> <span class="sy1">&lt;&lt;</span> <span class="st0">"2"</span><span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span><span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw2">class</span> Multiple <span class="sy4">:</span> <span class="kw2">public</span> DerivedOne, DerivedTwo</pre></li><li class="li1"><pre class="de1"> <span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> <span class="kw2">public</span><span class="sy4">:</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">void</span> print<span class="br0">(</span><span class="br0">)</span> <span class="kw4">const</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> DerivedTwo<span class="sy4">::</span><span class="me2">print</span><span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span><span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> Multiple both<span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> DerivedOne one<span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> DerivedTwo two<span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> Base <span class="sy2">*</span>array<span class="br0">[</span> <span class="nu0">3</span> <span class="br0">]</span><span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> array<span class="br0">[</span> <span class="nu0">0</span> <span class="br0">]</span> <span class="sy1">=</span> <span class="sy3">&amp;</span>both<span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> array<span class="br0">[</span> <span class="nu0">1</span> <span class="br0">]</span> <span class="sy1">=</span> <span class="sy3">&amp;</span>one<span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> array<span class="br0">[</span> <span class="nu0">2</span> <span class="br0">]</span> <span class="sy1">=</span> <span class="sy3">&amp;</span>two<span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">for</span> <span class="br0">(</span> <span class="kw4">int</span> i <span class="sy1">=</span> <span class="nu0">0</span><span class="sy4">;</span> i <span class="sy1">&lt;</span> <span class="nu0">3</span><span class="sy4">;</span> i<span class="sy2">++</span> <span class="br0">)</span></pre></li><li class="li1"><pre class="de1"> array<span class="br0">[</span> i <span class="br0">]</span> <span class="sy2">-</span><span class="sy1">&gt;</span> print<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">return</span> <span class="nu0">0</span><span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span></pre></li></ol></div></div></div></div></div></div>
Options:
121
212
12
215
Answer: B