Chapter 7、面向对象(一)--- 概述

 1 package com.hanqi;
 2 
 3 //鳥類
 4 public class Bird {  
 5 
 6     //屬性:成員變量
 7     String Colour;//顏色
 8     double Weight;//重量
 9     
10     //行為:方法
11     void fly() //
12     { 
13         System.out.println("我能飛");
14     }
15     void eat() //
16     {
17         System.out.println("我吃蟲子");
18     }     
19     
20     
21     public static void main(String[]args){
22         //生成一隻鳥的實例:老鷹
23         Bird eagle=new Bird();
24         eagle.Colour="灰色";
25         eagle.Weight=10;
26         System.out.println("這是一隻"+eagle.Colour+eagle.Weight+"斤的鳥");
27         
28         eagle.fly();
29         eagle.eat();
30         
31     }
32         
33 
34     }

原文地址:https://www.cnblogs.com/xiao55/p/5239981.html