面向对象编程(OOP)

 1 package com.hanqi;
 2 
 3 //鸟类
 4 public class Bird {
 5     //属性  成员变量
 6     //颜色
 7     String Color;
 8     //重量
 9     double Weight;
10     //行为  方法
11     
12     //飞  void - 没有返回值
13     void fly()
14     {
15         System.out.println("我能飞");
16     }
17     //
18     void eat()
19     {
20         System.out.println("我喜欢吃虫子");
21     }
22     
23     public static void main(String[] atgs)
24     {
25         //生成一只鸟的实例-老鹰
26         Bird eagle = new Bird();
27         eagle.Color = "灰色";
28         eagle.Weight = 10;
29         System.out.println("这是一只鸟,颜色是"+eagle.Color);
30         eagle.fly();    //相当于System.out.println("我能飞"); 这里是引用void定义的fly
31         eagle.eat();
32     }
33 }

运行结果为:

附课堂老师所讲的思维导图:

原文地址:https://www.cnblogs.com/hanazawalove/p/5235496.html