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
Why do we use polymorphism?
Why oops is important?
What is abstract class in oop?
What are the three main types of variables?
what type of questions
What does I oop mean?
What is the difference between inheritance and polymorphism?
Can static class have constructor?
How long to learn object oriented programming?
Can private class be inherited?
What is oops with example?
Is this job good for future? can do this job post grduate student?
What are the benefits of oop?
What does sksksk mean in text slang?
What is overloading and its types?