C++中的简单继承
Father.cpp:
1 #include<iostream> 2 using namespace std; 3 class Father 4 { 5 protected: 6 int width; 7 int height; 8 public: 9 void setWidth(int widths) 10 { 11 width = widths; 12 } 13 void setHeight(int heights) 14 { 15 height = heights; 16 } 17 }; 18 19 class Son : public Father 20 { 21 private: 22 int weight; 23 public: 24 void setWeight(int weights) 25 { 26 weight = weights; 27 } 28 void show() 29 { 30 cout<<"width ="<<width<<"\t"<<"height="<<height<<"\t"<<"weight="<<weight<<endl; 31 } 32 }; 33 34 int main() 35 { 36 Son a; 37 a.setWeight(100); 38 a.setHeight(180); 39 a.setWidth(70); 40 a.show(); 41 return 0; 42 }
运行结果:

posted on 2013-08-20 10:19 leihupqrst 阅读(211) 评论(0) 收藏 举报
浙公网安备 33010602011771号