系列: Angelia
java
18 行
· 更新于 2026-09-27
PremiumPointsAccount.java
Angelia/Java/Week_6_7/code/01_encapsulation/PremiumPointsAccount.java
/**
* 高級點數帳戶:繼承(extends)PointsAccount,只改寫 deposit。
*
* 用來示範「動態分派」(dynamic dispatch):
* PointsAccount a = new PremiumPointsAccount();
* a.deposit(500); // 執行的是 PremiumPointsAccount 的 deposit,而不是 PointsAccount 的
*/
public class PremiumPointsAccount extends PointsAccount {
/** 高級會員:存入金額先乘 1.1,再交給父類別處理(父類別再送 1%)。 */
@Override
public void deposit(int amount) {
if (amount < 0) {
throw new IllegalArgumentException("點數不可為負數:" + amount);
}
super.deposit(amount * 110 / 100); // super.deposit:呼叫父類別的版本
}
}
相关文章
Angelia
haskell
EN
更新于 2026-02-03
Adding.hs
Adding.hs — haskell source code from the Angelia learning materials (Angelia/Haskell/Adding.hs).
阅读文章 →
Angelia
haskell
EN
更新于 2026-02-03
Area.hs
Area.hs — haskell source code from the Angelia learning materials (Angelia/Haskell/Area.hs).
阅读文章 →
Angelia
haskell
EN
更新于 2026-02-03
Chess.hs
Chess.hs — haskell source code from the Angelia learning materials (Angelia/Haskell/Chess.hs).
阅读文章 →
Angelia
haskell
EN
更新于 2026-02-03
ChessGraphics.hs
ChessGraphics.hs — haskell source code from the Angelia learning materials (Angelia/Haskell/ChessGraphics.hs).
阅读文章 →
Angelia
haskell
EN
更新于 2026-02-03
Examples.hs
Examples.hs — haskell source code from the Angelia learning materials (Angelia/Haskell/Examples.hs).
阅读文章 →
Angelia
haskell
EN
更新于 2026-02-03
Fibonacci.hs
Fibonacci.hs — haskell source code from the Angelia learning materials (Angelia/Haskell/Fibonacci.hs).
阅读文章 →