Use of Protected(Access Specifier) :-


#include<iostream.h>
#include<conio.h>

class shape
{
protected:
int width,height;
public:
void enterwidth(int w)
{
width=w;
}
void enterheight(int h)
{
height=h;
}
};

class rectangle:public shape
{
 public:
  int area()
  {
  return (width*height);
  }
};

void main()
{
clrscr();
rectangle r1;
r1.enterwidth(5);
r1.enterheight(4);
cout<<"Area of Rectangle is:"<<r1.area();
getch();
}

Output:


Area of Rectangle is:20

			

Previous Next