oop prac4 inheritanceandpolymorphism
oop prac4 inheritanceandpolymorphism
INSTITUTE OF TECHNOLOGY
DHULE (M.S.)
DEPARMENT OF COMPUTER ENGINEERING
Remark
Subject : OOP lab
SHAPES
Block diagram
#include <iostream>
class shape
{
public:
void showshape()
{
cout<<"\n \nshape -";
}
};
}
};
}
};
}
};
int main ()
{
square s1;
circle c1;
triangle t1;
s1.show();
c1.show();
t1.show();
return 0;
}
Output:
shape -
square
shape -
Circle
shape -
triangle
#include <iostream>
using namespace std;
class A
{
protected:
int x;
int a,b;
public:
void show()
{
cout<<"\n Polymorphism";
}
void show(int x)
{
cout<<"\n Also know as function overloding";
}
void show(int a,int b)
{
cout<<"\n Addition A+B is = "<<a+b;
}
};
int main ()
{
A a1;
a1.show();
a1.show(3);
a1.show(10,20);
return 0;
}
Output:
Polymorphism
Also know as function overloding
Addition A+B is = 30
#include <iostream>
class A
{
protected:
int a=10;
public:
void show()
{
cout<<" Printing A : "<<a;
}
};
class B:public A
{
protected:
int b=20;
public:
void show()
{
cout<<"\n Printing B : "<<b;
}
};
class C:public B
{
private:
int c=30;
public:
void show()
{
cout<<"\n Printing C : "<<c;
}
};
int main()
{
A a1;
B b1;
C c1;
a1.show();
b1.show();
c1.show();
return 0;
}
Output:
Printing A : 10
Printing B : 20
Printing C : 30