Multiple choice

Which of the following is the correct syntax to call the parameterized constructor of class 'sample' from the constructor of class 'sub'?

class sample {
 public:
  sample(int a) {}
};
class sub {};

  1. sub(int x,int y) : sample(x)

  2. sub(int x,int y) { sample(y); }

  3. sub(int x,int y) , sample(x)

  4. sub(int x,int y) : sample{x}

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In the process of inheritance, if the base class has a parameterized constructor the derived class should also have a parameterized constructor. Therefore, if the parent class of constructor takes an integer value as input, the value must be passed from the child class constructor to the parent class constructor.