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
Why do we need oop?
How do you explain polymorphism?
What is destructor example?
What are different types of JVM's? for example we use dalvik jvm for android then what about the remaining operating systems?
can we make game by using c
what is graphics
What are the three parts of a simple empty class?
class type to basic type conversion
What is pointer in oop?
They started with the brief introduction followed by few basic C++ questions on polumorphism, inheritance and then virtual functions. What is polymorphims? How you will access polymorphic functions in C? How virtual function mechanism works?
Where You Can Use Interface in your Project
hi, this is raju,iam studying b.tech 2nd year,iam want know about group1 and group2 details, and we can studying without going to any instutions? please help me.
What is byval and byref? What are differences between them?
Which is better struts or spring?
What is the fundamental idea of oop?