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


Please Help Members By Posting Answers For Below Questions

c++ program to swap the objects of two different classes

1761


What does and I oop mean?

613


How long to learn object oriented programming?

562


What are the features of oop?

635


What are the three main types of variables?

600






write knight tour problem which is present in datastructure

2162


What do you mean by variable?

572


when to use 'mutable' keyword and when to use 'const cast' in c++

1642


What does no cap mean?

590


Why do we use inheritance?

628


Write a java applet that computes and displays the squares of values between 25 and 1 inclusive and displays them in a TextArea box

2030


i got a backdoor offer in process global,Bangalore..Can i work with it?

2324


Why do we need polymorphism in c#?

684


Which method cannot be overridden?

576


what are the realtime excercises in C++?

2333