CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS LANGUAGES C++ DETAILS
Question :
What is virtual class and friend class?
Category C++ Interview Questions
Rating (5.0) By 1 users
Added on 7/19/2006
Views 3065
Rate it!
Answers:

Friend classes are used when two or more classes are designed to work together and virtual base class aids in multiple inheritance



Friend Class: This is a commitment from the class where the other class is declared as Friend Class.

If Class B declared as a friend class in Class A, theb B has the access to all the members and functions (private, public and protected). But here the reverse is not true. i.e. A does not have the same priveleges over B.

Virtual Function:
During Multiple inheritance when a class is derived from two different classes having a common function, then teh derived class contains 2 different copies of the common function. The virtual key word is used there to avoid having 2 copies of the same functin.

Example:

Class A{
Public:
Func();
}

Class B:virtual public A{
}
Class C:virtual public A{
}
Class D:public B,public D
{
}

Here in the above example B, C inherit the same copy of Func(). Now D inherits teh same Func() from B and C. The Virtual keyword is used to avoid this.



 Posted by: Manas Ranjan Padhy    

Contact Manas Ranjan Padhy  Contact Manas Ranjan Padhy


If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
What is function overloading and operator overloading?


View Answer
Difference between realloc() and free()?


View Answer
What do you mean by binding of data and functions?


View Answer
What is friend function?


View Answer
What is public, protected & private?


View Answer
What is polymorphism? Explain with an example?


View Answer
What is a class?


View Answer
What is the difference between structures and classes in C++?
View Answer
What is an object?


View Answer
What is the difference between class and structure?


View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL C++ Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/6154/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

0.66