Question: 8. 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> BaseClass </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> myFunction<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"> <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> DerivedClass1 <span class="sy4">:</span> <span class="kw2">public</span> BaseClass </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> myFunction<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"> <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> DerivedClass2 <span class="sy4">:</span> <span class="kw2">public</span> DerivedClass1 </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> myFunction<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"> <span class="kw3">cout</span> <span class="sy1">&lt;&lt;</span> <span class="st0">"3"</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"> BaseClass <span class="sy2">*</span>p<span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> BaseClass ob<span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> DerivedClass1 derivedObject1<span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> DerivedClass2 derivedObject2<span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> p <span class="sy1">=</span> <span class="sy3">&amp;</span>ob<span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> p <span class="sy2">-</span><span class="sy1">&gt;</span> myFunction<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> p <span class="sy1">=</span> <span class="sy3">&amp;</span>derivedObject1<span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> p <span class="sy2">-</span><span class="sy1">&gt;</span> myFunction<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> p <span class="sy1">=</span> <span class="sy3">&amp;</span>derivedObject2<span class="sy4">;</span></pre></li><li class="li1"><pre class="de1"> p <span class="sy2">-</span><span class="sy1">&gt;</span> myFunction<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:
123
12
213
321
Answer: A