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 oops concept with example?
What is for loop and its syntax?
How to call a non virtual function in the derived class by using base class pointer
What is persistence in oop?
What is oops in simple words?
What are the 3 pillars of oop?
why reinterpret cast is considered dangerous?
write a programe to calculate the simple intrest and compund intrest using by function overlading
What is polymorphism programming?
i=20;k=0;
for(j=1;k-i;k+=j<10?4:3)
{
cout< Why do we use polymorphism in oops? Question:
Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and
Monthly. An appointment has a description (for example, “see the dentist”) and a date
and time. Write a virtual function occurs_on(int year, int month, int day) that checks
whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill a vector of
Appointment* with a mixture of appointments. Have the user enter a date and print out
all appointments that happen on that date. What is oops and its features? What is the significance of classes in oop? What is a null tree?