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
What is the real time example of encapsulation?
What is stream in oop?
What is constructor overloading in oop?
Why is there no multiple inheritance?
write a program to find 2 power of a 5digit number with out using big int and exponent ?
class type to basic type conversion
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).
What are classes oop?
How do you answer polymorphism?
What is the example of polymorphism?
What is the benefit of oop?
What is the real time example of inheritance?
What is protected in oop?
What is coupling in oops?
How to improve object oriented design skills?