课外天地 李树青学习天地Java程序语言课件 → [推荐]Java授课视频第八课:面向对象——多态


  共有18839人关注过本帖树形打印复制链接

主题:[推荐]Java授课视频第八课:面向对象——多态

帅哥哟,离线,有人找我吗?
admin
  1楼 博客 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 管理员
等级:管理员 帖子:1938 积分:26572 威望:0 精华:34 注册:2003/12/30 16:34:32
[推荐]Java授课视频第八课:面向对象——多态  发帖心情 Post By:2011/5/22 13:39:26 [只看该作者]

媒体文件信息
文件来源:http://www.njcie.com/JavaSE/files/第八课:面向对象多态.wmv
您可以点击控件上的播放按钮在线播放。注意,播放此媒体文件存在一些风险。
附加说明:动网论坛系统禁止了该文件的自动播放功能。
由于该用户没有发表自动播放多媒体文件的权限或者该版面被设置成不支持多媒体播放。

 回到顶部
帅哥哟,离线,有人找我吗?
admin
  2楼 博客 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 管理员
等级:管理员 帖子:1938 积分:26572 威望:0 精华:34 注册:2003/12/30 16:34:32
课上代码——银行货币处理  发帖心情 Post By:2011/5/22 13:40:41 [只看该作者]

class Currency {
        private double amount;
        private String type;

        public Currency() {

        }

        public Currency(double amount) {
                setAmount(amount);

        }

        public double getAmount() {
                return amount;
        }

        public void setAmount(double amount) {
                this.amount = amount;
        }

        public String getType() {
                return type;
        }

        public void setType(String type) {
                this.type = type;
        }

        public String toString() {
                return type + amount;
        }
}

class Yuan extends Currency {
        public Yuan() {
                setType("Y");
        }

        public Yuan(double amount) {
                setAmount(amount);
                setType("Y");
        }

}

class Dollar extends Currency {
        public Dollar() {
                setType("$");
        }

        public Dollar(double amount) {
                setAmount(amount);
                setType("$");
        }
}

class Transaction {
        public void action(Currency a, double amount) {
                a.setAmount(amount);
                System.out.println(a);
        }
}

class Pound extends Currency
{
        public Pound() {
                setType("GBP");
        }
        public Pound(double amount) {
                setAmount(amount);
                setType("GBP");
        }
}

public class Exec {
        public static void main(String[] args) {
                Transaction tran1 = new Transaction();
                tran1.action(new Yuan(), 2000);
                tran1.action(new Dollar(), 3000);
                tran1.action(new Pound(), 500);
        }
}

[此贴子已经被作者于2011-05-22 13:42:09编辑过]

 回到顶部