首页 > 其他 > 详细

Chapter 7、面向对象(一)

时间:2016-03-03 21:21:45      阅读:241      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!