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

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

1653


What is protected in oop?

615


What is polymorphism and types?

611


Will I be able to get a picture in D drive to the c++ program? If so, help me out?

1671


write string class as your own class in java without using any built-in function

1984






What are the data types in oop?

615


Why do pointers exist?

671


Can main method override?

593


Which is not an object oriented programming language?

551


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.

1801


How do you answer polymorphism?

590


what are the ways in which a constructors can be called?

1590


What exactly is polymorphism?

616


What is class in oop with example?

631


Can a destructor be called directly?

613