Base class has two public data members. How can i derive a
new class with one datamember as public and another data
member as private?.
Answer Posted / iyappan
just have a look on the given program. Then you can get
idea about it.
class base
{
public:
virtual void fun1(){printf("I am base class public
fun1");}
virtual void fun2(){printf("I am base class public
fun2");}
};
class derived:public base
{
void fun1(){printf("I am derived class private
fun1");}
public:
void fun2(){printf("I am derived class public
fun2");}
};
int main()
{
derived obj;
obj.fun1();//it will show compile time error.
because this is private member of derived class
obj.fun2();//it will work fine.
base *ptr = &obj;
ptr->fun1();//it will work fine.
ptr->fun2();//it will work fine.
}
Is This Answer Correct ? | 2 Yes | 3 No |
Post New Answer View All Answers
when to use 'mutable' keyword and when to use 'const cast' in c++
What is protected in oop?
What is polymorphism and types?
Will I be able to get a picture in D drive to the c++ program? If so, help me out?
write string class as your own class in java without using any built-in function
What are the data types in oop?
Why do pointers exist?
Can main method override?
Which is not an object oriented programming language?
write a program to enter a string like"sunil is a good boy and seeking for a job" not more than 10 characters including space in one line,rest characters should b in other line.if the next line starts from in between the previous word,then print whole word to next line.
How do you answer polymorphism?
what are the ways in which a constructors can be called?
What exactly is polymorphism?
What is class in oop with example?
Can a destructor be called directly?