Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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?.

Answers were Sorted based on User's Feedback



Base class has two public data members. How can i derive a new class with one datamember as public..

Answer / deepak sharma

class base
{
public:

base(int d1 = 5, int d2 = 6) : data1(d1), data2(d2)
{ }
int data1, data2;
};

class der:public base
{
private:
using base::data1; //Making data1 of class base
private, explicitliy,
//you can make member functions private or
protected this way
};

int main(int argc, char* argv[])
{
der obj1;
cout<<obj1.data1<<endl; //Error : 'data1' : cannot
access private member declared in class 'der'
cout<<obj1.data2<<endl; //Works fine
return 0;
}

Is This Answer Correct ?    9 Yes 0 No

Base class has two public data members. How can i derive a new class with one datamember as public..

Answer / 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

More OOPS Interview Questions

What is overriding in oops?

0 Answers  


Explain the concepts involved in Object Oriented programming.

0 Answers   Wipro,


What is encapsulation in simple terms?

0 Answers  


why to use template classes in c++?

1 Answers  


I hv a same function name,arguments in both base class and dervied class, but the return type is different. Can we call this as a function overloading? Explain?

3 Answers  


What are the benefits of interface?

0 Answers  


What is oops in simple words?

0 Answers  


which is platform independent device used in computers

2 Answers  


What is difference between abstraction and encapsulation?

0 Answers  


What is polymorphism? Explain with an example.

48 Answers  


What is the real time example of encapsulation?

0 Answers  


There are two base class B1,B2 and there is one class D which is derived from both classes, Explain the flow of calling constructors and destructors when an object of derived class is instantiated.

0 Answers  


Categories