Inheritance, Poly Morphism | Introduction | CPP OOPS

  c++

Email

#include<iostream>
#include<string>

using namespace std;
class Anil{
public :
string name;
int age;

void setname(string iname)
{
name = iname;

}
void setage(int iage)
{
age=iage;
}

};
class Book : public Anil{
public :
int id;

void setid(int iid){
id=iid;

}

void desipyaly()
{
cout << name << age << id;
}

};

int main(){

Book naik;
naik.setname(“anilnaikn”);
naik.setage(12);
naik.setid(123456);
naik.desipyaly();

return 0;
}

Spread the Code

Leave a Reply

avatar

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
Notify of