面向对象

 1 package 面向对象;
 2 //鸟类
 3 public class Brid {
 4     //属性 成员变量
 5     
 6     //颜色
 7     String Color;
 8     //重量
 9     double Weight;
10     //行为   用方法来表示
11     
12     //
13     void fly()
14     {
15         System.out.println("I can fly");
16     }
17     //
18     void eat()
19     {
20         System.out.println("我喜欢吃虫子");
21     }
22     public static void main(String[] args)
23     {
24         //生成一直鸟的实例      老鹰
25         Brid eagle =new Brid();
26         eagle.Color="灰色";
27         eagle.Weight=10;
28         
29         System.out.println("这是一只鸟 颜色是:"+eagle.Color);
30         eagle.fly();
31         eagle.eat();
32     }
33 
34 }
View Code

原文地址:https://www.cnblogs.com/beens/p/5235481.html