3 years ago in C++ Inheritance

what will the ouput of the following code be?

#include

using namespace std;

class parent
{
public:
int x, y;
parent(int a, int b) { x = a; y = b; }
parent() { x = y = 0; }
void print() { cout << x << " " << y << " "; }
};

class child : public parent
{
public:
int a, b;
child(int a, int b) { this->a = a; this->b = b; }
void print() { cout << x << " " << y << " " << a << " " << b << " "; }
};

int main()
{
parent p(3,4);
child c(1,2);
p = (parent)c;
c.print();
p.print();
return 0;
}

[A] 0 0 1 2 0 0
[B] 0 0 1 2 3 4
[C] 3 4 1 2 3 4
[D] Compiler error
Loading...
Next Question

Overall Stats

Attempted 7
Correct 0
Incorrect 4
Viewed 3

Answers

Guest
Guest
GAUTAM KUMAR
GAUTAM KUMAR - 2 years ago

GAUTAM KUMAR from Manpur, Bihar is saying 0 0 1 2 3 4 is correct answer

GAUTAM KUMAR
GAUTAM KUMAR - 2 years ago

GAUTAM KUMAR from Manpur, Bihar is saying 0 0 1 2 3 4 is correct answer

GAUTAM KUMAR
GAUTAM KUMAR - 2 years ago

GAUTAM KUMAR from Manpur, Bihar is saying 0 0 1 2 3 4 is correct answer

Gautam Kumar
Gautam Kumar - 2 years ago

Gautam Kumar from Gaya, India is saying Compiler error is correct answer

Related Questions

Which design patterns benefit from the multiple inheritance?

  • [A] Adapter and observer pattern
  • [B] Code pattern
  • [C] Glue pattern
  • [D] None of the mentioned

The conversion from basic data to class type can be done by .......

  • [A] Writing constructor
  • [B] Is not possible
  • [C] overloaded casting operator
  • [D] object of a class

Choose most appropriate statement

  • [A] An abstract base class can have pure virtual destructor
  • [B] An abstract base class can have only virtual destructor
  • [C] An abstract base class can have non virtual destructor
  • [D] An abstract base class cannot have destructor

A base class will offer

  • [A] offer more specific objects than its derived classes
  • [B] correspond to something in the rest world
  • [C] behave badly when the chops are down
  • [D] be a generalized version of its derived classes

Which symbol is used to create multiple inheritance?

  • [A] Dot
  • [B] Comma
  • [C] Dollar
  • [D] None of the mentioned