码迷,mamicode.com
首页 > 其他好文 > 详细

Chapter 7、面向对象(一)

时间:2016-03-03 21:24:17      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 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     }

技术分享

Chapter 7、面向对象(一)

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!