ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C++  >>  OOPS
 
 


 

 
 STL interview questions  STL Interview Questions
 OOPS interview questions  OOPS Interview Questions
 C++ General interview questions  C++ General Interview Questions
Question
suppose A is a base class and B is the derved class. Both 
have a method foo which is defined as a virtual method in 
the base class. You have a pointer of classs B and you 
typecast it to A. Now when you call pointer->foo, which 
method gets called?

The next part of the question is, how does the compiler 
know which method to call?
 Question Submitted By :: Nm
I also faced this Question!!     Rank Answer Posted By  
 
  Re: suppose A is a base class and B is the derved class. Both have a method foo which is defined as a virtual method in the base class. You have a pointer of classs B and you typecast it to A. Now when you call pointer->foo, which method gets called? The next part of the question is, how does the compiler know which method to call?
Answer
# 1
The answer is that B->foo gets calle, and why ? I found a 
good explanation of that here:

http://en.wikipedia.org/wiki/Virtual_table
 
Is This Answer Correct ?    1 Yes 0 No
Nm
 
  Re: suppose A is a base class and B is the derved class. Both have a method foo which is defined as a virtual method in the base class. You have a pointer of classs B and you typecast it to A. Now when you call pointer->foo, which method gets called? The next part of the question is, how does the compiler know which method to call?
Answer
# 2
It depends the pointer points to the object of which class. 
If the pointer points to Class A, then the method defined 
in class A will be called, and if the pointer points to 
class B, then the method defined in class B will be called.
 
Is This Answer Correct ?    0 Yes 0 No
Suchi
 
 
 

 
 
 
Other OOPS Interview Questions
 
  Question Asked @ Answers
 
When is it necessary to use member-wise initialization list in C++?  1
Difference between over loading and over ridding? CTS10
how to swap to variables without using thrid variable in java?  3
Please tell me the oops concept with detailed answer EEE4
When is an object created and what is its lifetime? IBM1
what is the usage of clas templates  5
What is Inheritance, Multiple Inheritance, Shared and Repeatable Inheritance? Accenture3
Difference between realloc() and free? HP3
What is polymorphism ? Explain with examples Ness-Technologies6
What is Dynamic Polymorphism?  6
How is exception handling carried out in c++?  1
In which Scenario you will go for Interface or Abstract Class?  1
What is a scope resolution operator? HP4
In multilevel inheritance constructors will be executed from the .... class to ... class  1
Which is the only operator in C++ which can be overloaded but NOT inherited?  3
what is diff between .net 1.1 and .net 2.0  3
When is a memory allocated to a class?  3
What is a mixin class?  3
What is a class? TCS17
write a c++ program to find maximum of two numbers using inline functions.  1
 
For more OOPS Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com