xFactorSchool.com(Beta)
How to Do Examples
Python Examples
HTML Examples
Code Examples
C Code Examples
C++ Code Examples
C# Code Examples
Java Code Examples
Python Code Examples
HTML Code Examples
CSS Code Examples
JavaScript Code Examples
Online Editor
C Code Editor
C++ Code Editor
C# Code Editor
Java Code Editor
Python Code Editor
HTML Code Editor
CSS Code Editor
JavaScript Code Editor
Practice how to inherit a class in C++
C++ Online Editor
Execute Code
More C++ Sample Code
#include <iostream> #include <string> using namespace std; // use std namespace to avoid std:: before cout // This is the base (parent) class class Person { public: string Name; int Age; }; // This is the derived (child) class inheriting from the base (Person) class class Student : public Person { public: int StudentId; }; int main() { Student studentObj; // studentObj is an object of the Student class studentObj.Name = "John"; // Assign value to the Name property studentObj.Age = 15; // Assign value to the Age property studentObj.StudentId = 11; // Assign value to the StudentId property cout << studentObj.Name << " is " << studentObj.Age << " years old. His student id is " << studentObj.StudentId << "." << endl; return 0; }