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 }
View Code

相关文章:

  • 2022-12-23
  • 2021-07-04
  • 2021-05-07
  • 2021-10-09
  • 2021-06-14
  • 2022-12-23
  • 2022-12-23
  • 2022-02-06
猜你喜欢
  • 2022-12-23
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-30
  • 2022-12-23
相关资源
相似解决方案