# 物件導向程式設計之應用與練習 Object Oriented Programming by Ivor Chu 問題描述 請使用物件導向概念設計一隻程式,內容包括下列要求: 1. CMath 類別有一個 getMax()方法,他可以比較兩個傳入引述值並顯示最大值。 2. SonCMath 類別繼承了 CMath 類別,除具有 CMath 類別的getMax() 方法外,他另外定義了一個能產生階乘的 getFactorial() 方法。 3. SonCMath 類別再往下延伸出 GrandSonCMath 子類別,而且這個子類別另外定義了能回傳兩數平均的 getAverage() 方法。 輸入格式(此操作將執行於主程式 以Java為例) ``` public static void main(String[] args) { SonCMath math1 = new SonCMath(); // 創建SonCMath物件 math1.getMax(10, 20); // 呼叫子類別繼承父類別的方法 System.out.println(); // 換行 math1.getFactorial(5); // 呼叫子類別自己的方法 System.out.println(); // 換行 GrandSonCMath math2 = new GrandSonCMath(); // 創建GrandSonCMath物件 math2.getMax(20, 30); // 呼叫繼承自祖父類別的方法 System.out.println(); // 換行 math1.getFactorial(6); // 呼叫繼承自祖父類別的方法 System.out.println(); // 換行 math2.getAverage(12, 34); // 呼叫用自己的方法 System.out.println(); // 換行 } ``` 輸出格式 ``` >>> 20 >>> 120 >>> 30 >>> 720 >>> 23 ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up