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
INSTANCE FIELDS DECLARED private ARE ACCESSIBLE BY THE METHODS ONLY.CAN WE CHANGE THE private FIELD OF AN OBJECT IN A METHOD OF SOME OTHER OBJECT OF THE SAME CLASS?
what are the different types of qualifier in java?
What does no cap mean?
What is multilevel inheritance explain with example?
What is encapsulation c#?
What is the problem with multiple inheritance?
Prepare me a program for the animation of train
What does oop mean in snapchat?
Which is better struts or spring?
What are different types of JVM's? for example we use dalvik jvm for android then what about the remaining operating systems?
Why do we need oop?
What does and I oop mean?
What is super in oop?
They started with the brief introduction followed by few basic C++ questions on polumorphism, inheritance and then virtual functions. What is polymorphims? How you will access polymorphic functions in C? How virtual function mechanism works?
Can we have inheritance without polymorphism?