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
What is for loop and its syntax?
when to use 'mutable' keyword and when to use 'const cast' in c++
what are the ways in which a constructors can be called?
What is encapsulation in oops?
What is abstraction with example?
Why it is called runtime polymorphism?
What are the important components of cohesion?
This program numbers the lines found in a text file. Write a program that reads text from a file and outputs each line preceded by a line number. Print the line number right-adjusted in a field of 3 spaces. Follow the line number with a colon, then one space, then the text of the line. You should get a character at a time and write code to ignore leading blanks on each line. You may assume that the lines are short enough to fit within a line on the screen. Otherwise, allow default printer or screen output behavior if the line is too long (i.e., wrap or truncate). A somewhat harder version determines the number of spaces needed in the field for the line numbers by counting lines before processing the lines of the file. This version of the program should insert a new line after the last complete word that will fit within a 72-character line.
What is abstraction in oop with example?
Why is polymorphism important in oop?
IS IT NECESSARY TO INITIALIZE VARIABLE? WHAT IF THE INSTANCE VARIABLE IS DECLARED final ? IS IT NECESSARY TO INITIALIZE THE final VARIABLE AT THE TIME OF THEIR DECLARATION?
What is constructor in oop?
Why is abstraction needed?
Is abstract thinking intelligence?
What type of loop is a for loop?