Java 程式設計 -- 物件導向中的封裝特性
Java 程式簡介運算式分枝迴圈陣列函數遞迴錯誤處理物件導向封裝繼承多型技巧函式庫字串數學正規表達式容器檔案網路資料庫視窗ThreadListener錯誤陷阱相關檔案相關資源教學錄影Eclipse考題解答訊息相關網站參考文獻最新修改簡體版English |
範例一:人的體重class Object1 { public static void main(String args[]) { Person1 p1, p2; p1 = new Person1("大雄", 50); p2 = new Person1("胖虎", 80); p1.checkWeight(); p2.checkWeight(); p2.weight = 68; p1.checkWeight(); p2.checkWeight(); } } class Person1 { String name; int weight; Person1(String pName, int pWeight) { name = pName; weight = pWeight; } void checkWeight() { System.out.print(name+"體重 "+weight+" 公斤,"); if (weight < 70) System.out.println("很苗條!"); else System.out.println("很穩重!"); } } |
page revision: 0, last edited: 04 Nov 2010 03:36
Post preview:
Close preview