59.5k views
2 votes
What is the output of the program?

#include
using namespace std;
class bClass
{
public:
void print() const;
bClass(int a = 0, int b = 0);
//Postcondition: x = a; y = b;
private:
int x;
int y;
};
class dClass: public bClass
{
public:
void print() const;
dClass(int a = 0, int b = 0, int c = 0);
//Postcondition: x = a; y = b; z = c;
private:
int z;
};
int main()
{
bClass bObject(2, 3);
dClass dObject(3, 5, 8);
bObject.print();
cout << endl;
dObject.print();
cout << endl;
return 0 ;
}
void bClass::print() const
{
cout << x << " " << y << endl;
}
bClass::bClass(int a, int b)
{
x = a;
y = b;
}
void dClass::print() const
{
bClass::print(); //added second colon
cout << " " << z << endl;
}
dClass::dClass(int a, int b, int c)
: bClass(a, b)
{
z = c;
}

User Arbaaz
by
5.3k points

1 Answer

5 votes

Answer:

The output to this program is :

2 3

3 5

8

Explanation:

The description of the given c++ program can be given as:

  • In the given c++ program two class is defined that is "class bClass and class dClass". In bClass, this class declares a method, parameterized constructor, and private integer variable x and y. In dClass, this class first, inherit the base class that is bClass and this class also declares a method, parameterized constructor, and private integer variable z.
  • In the main method, we create the class object and passed value in the constructor parameter that is "2, 3" and "3, 5, 8" and call the function that is "print".
  • In this method, we use the scope resolution operator that access function and constructor to main method scope. By using a scope resolution operator we define method and constructor.
User Robert Karl
by
5.7k points