Encapsulation in c++

Encapsulation in c++


  1. #include<iostream>  
  2. using namespace std;  
  3.   
  4. class Shape{  
  5. private:  
  6.     int l,w,h;  
  7. public:  
  8.     Shape(int l,int w,int h){  
  9.         this->l=l;  
  10.         this->w=w;  
  11.         this->h=h;  
  12. //        l=a;  
  13. //        w=b;  
  14. //        h=c;  
  15.     }  
  16.     void getRectangle(){  
  17.         cout<<l*w<<endl;  
  18.     }  
  19. };  
  20.   
  21. int main()  
  22. {  
  23.     Shape s(2,4,7);  
  24.     s.getRectangle();  
  25.     return 0;  
  26. }
Share:

0 Comments:

Post a Comment