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
Explain the concepts involved in Object Oriented programming.
Advantage and disadvantage of routing in telecom sector
Why is polymorphism used?
What is a class in oop?
What is abstraction with example?
Which language is pure oop?
What is encapsulation in ict?
What is the benefit of oop?
Write a program to compute for numeric grades for a course. The course records are in a file that will serve as the input file. The input file is in exactly the following format: Each line contains a student's first name, then one space, then ten quiz scores all on one line. The quiz scores are in whole number and are separated by one space. Your program will take it input from this file and sends it output to a second file. The data in the output file will be exactly the same as the data in the input file except that there will be one additional number (of type double) at the end of each line. This number will be the average of the student's ten quiz scores. Use at least one function that has file streams as all or some of its arguments.
What is the oops and benefits of oops programming?
What is multilevel inheritance in oop?
#include
Following are the class specifications: class {int a}; class {int b}; Using friend funtion,calculate the max of two objects and display it.
Is this job good for future? can do this job post grduate student?
What is the fundamental idea of oop?