Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inheritance #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions correct_multiple_inheritance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//multiple inheritance i.e a class inherits from more than one class
//Dtyagi-9
#include <iostream>
using namespace std;
class A
{

public:
int a,b;
A(){
a=0;
b=0;
};
A(int p,int q)
{
a=p;
b=q;
}
void getdata()
{
cout<<"enter the values in a and b \n";
cin>>a>>b;

}


};
class C
{
public:
int c;
void readdata()
{
cout<<"enter the value of c";
cin>>c;

}
C()
{
c=0;
}


};
class B:public A,public C
{
public:

void display()
{
cout<<"THE VALUES OF A ,B AND C ARE: \n a="<<a<<"\n b="<<b<<"\n c="<<c;
}
};



int main()
{

B objB;
objB.getdata();
objB.readdata();
objB.display();


return 0;
}
//this code was written to study the errors that arise when 2 classes
//with same function names are called and then there is discrepancy during the runtime
//here the getdata function call is resolved as in class c name is changed
49 changes: 49 additions & 0 deletions inheritance1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//single level inheritance i.e taking one as a parent class and another as a child class
//Dtyagi-9
#include <iostream>
using namespace std;
class A
{

public:
int a,b;
A(){
a=0;
b=0;
};
A(int p,int q)
{
a=p;
b=q;
}
void getdata()
{
cout<<"enter the values in a and b \n";
cin>>a>>b;

}


};

class B:public A
{
public:

void display()
{
cout<<"THE VALUES OF A AND B ARE: \n a="<<a<<"\n b="<<b;
}
};



int main()
{

B objB;
objB.getdata();
objB.display();

return 0;
}