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

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the real time example of encapsulation?

1007


What is stream in oop?

1245


What is constructor overloading in oop?

1075


Why is there no multiple inheritance?

952


write a program to find 2 power of a 5digit number with out using big int and exponent ?

2322


class type to basic type conversion

2337


assume the program must insert 4 elements from the key board and then do the following programs.sequential search(search one of the elements),using insertion sort(sort the element) and using selection sort(sort the element).

2070


What are classes oop?

975


How do you answer polymorphism?

1005


What is the example of polymorphism?

1019


What is the benefit of oop?

999


What is the real time example of inheritance?

1079


What is protected in oop?

1009


What is coupling in oops?

1065


How to improve object oriented design skills?

945