1、继承
动物有 吃 睡 呼吸的方法 当然 鱼也有 不用重复再定义
1)public 那里都可以访问
1 #include <iostream.h> 2 class Animal //类 基类 3 { 4 public: 5 void eat()//吃方法 6 { 7 cout<<"animal eat "<<endl; 8 9 } 10 void sleep()//睡觉方法 11 { 12 cout<<"animal sleep"<<endl; 13 } 14 void breathe()//呼吸方法 15 { 16 cout<<"animal breathe"<<endl; 17 } 18 }; 19 class Fish: public Animal// //子类 20 { 21 22 23 }; 24 25 void main() 26 27 { 28 Animal an; 29 an.eat(); 30 Fish fh; 31 fh.sleep(); 32 }