Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Can we have a private virtual method ?

Answer Posted / ganesh mishra

yes... we can have private virtual method and will not give
any compile time/runtime error.but when we derive any class
from it and override the virtual function,then the compiler
will throw a compile time error.

//file name is privatever.cpp

#include <iostream>
using namespace std;

class base
{
virtual void fun()
{
cout <<"base class function"<<endl;
}

};

class derive: public base
{
public:
virtual void fun()
{
cout<<"derived class function"<<endl;
}
};

int main()
{
base *pt;
derive *der = new derive;
pt = der;
pt->fun();
return(0);
}

here is the error
privatever.cpp: In function ‘int main()’:
privatever.cpp:6: error: ‘virtual void base::fun()’ is private
privatever.cpp:27: error: within this context

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How is class defined?

1139


What is oops?what is its use in software engineering?

1032


what are the ways in which a constructors can be called?

2135


Why it is called runtime polymorphism?

1135


write a programe to calculate the simple intrest and compund intrest using by function overlading

2204


What is overloading in oops?

1160


What is Difeerence between List obj=new ArrayList(); and ArrayList obj=new ArrayList()?

2536


What is object in oop?

1116


what type of questions

2127


What are the components of marker interface?

1056


How does polymorphism work?

1139


Can static class have constructor?

1032


Can enum be null?

1019


What is debug class?what is trace class? What differences are between them? With examples.

2194


What is the diamond problem in inheritance?

1138