Can we have a private virtual method ?

Answer Posted / gopinath das

Yes , It we can have a private virtual method. It has
nothing to do with inheritance. It only resolve the dynamic
binding . Only difference is that , this method should be
used inside the class defination of the Base .
The derived class may implements the method either
public,private or protected.
Exa:

class A
{
virtual void x(){cout<<"A"<<endl;};
public:
};
class B:public A
{
//virtual void x(){cout<<"B"<<endl;}; // no prob
public:
virtual void x(){cout<<"B"<<endl;};
};
int main()
{
A *a;
B *b=new B;
a=b;
a->fn();
}
Out put:
B

Is This Answer Correct ?    4 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is polymorphism programming?

609


What are properties in oop?

615


What is purpose of inheritance?

653


Can main method override?

591


what are the realtime excercises in C++?

2337






class CTest { public: void someMethod() { int nCount = 0; cout << "This is some method --> " << nCount; } }; int main() { CTest *pctest; pctest->someMethod(); return 0; } It will executes the someMethod() and displays the value too. how is it possible with our creating memory for the class . i think iam not creating object for the class. Thanks in Advance... Prakash

1706


Question: Write a program that prints a paycheck. Ask the program user for the name of the employee, the hourly rate, and the number of hours worked. If the number of hours exceeds 40, the employee is paid “time and a half”, that is, 150 percent of the hourly rate on the hours exceeding 40. Be sure to use stepwi se refine ment and break your solution into several functions. Use the int_name function to print the dollar amount of the check.

709


What do you mean by abstraction?

624


Is enum a class?

611


Is html an oop?

587


What does and I oop mean?

622


What is property in oops?

573


write a program that takes input in digits and display the result in words from 1 to 1000

1995


What type of loop is a for loop?

690


What is encapsulation example?

553