Introduction to Inheritance in c++
This video tutorial explains the concept of inheritance in c++.
You will learn what is inheritance, what is the use of inheritance, how to implement inheritance in c++, how to create derived classes, what is a base class, how to inherit from a class in detail with example.
source code for this tutorial
#include <iostream> #include<string> using namespace std; class Person{ public: string name; int age; void setName(string iname){name = iname;} void setAge(int iage){age = iage;} }; class Student : public Person{ public: int id; void setId(int iid){id = iid;} void introduce(){ cout <<"hi iam "<<name<<" and i am "<<age<<" years old "<<endl<<"and my student id is "<<id; } }; int main() { Student anil; anil.setName("anil"); anil.setAge(24); anil.setId(12345); anil.introduce(); return 0; }