Back to track
#113 Medium Object-Oriented C++

Single Inheritance

Open the editor

Problem

Derive a class and call base methods.

Input

No input.

Output

Exactly what the described program prints.

Hints

  1. 1

    Use inheritance syntax

  2. 2

    Call d.speak(), d.bark()

Worked solution

Reference solution

One correct implementation. Alternative approaches that satisfy the constraints are equally valid — the reviewer judges behaviour, not style.

#include <iostream>
using namespace std;

class Animal {
public:
  void speak() const { cout << "sound" << '\n'; }
};

class Dog : public Animal {
public:
  void bark() const { cout << "bark" << '\n'; }
};

int main() {
  Dog d;
  d.speak();
  d.bark();
  return 0;
}

© 2026 ChitChat