Rss & SiteMap

课外天地 李树青 http://www.njcie.com

李树青 论坛 南京 财经 课外天地
共2 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

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

1楼
admin 发表于:2011/5/22 13:39:26
媒体文件信息
文件来源:http://www.njcie.com/JavaSE/files/第八课:面向对象多态.wmv
您可以点击控件上的播放按钮在线播放。注意,播放此媒体文件存在一些风险。
附加说明:动网论坛系统禁止了该文件的自动播放功能。
由于该用户没有发表自动播放多媒体文件的权限或者该版面被设置成不支持多媒体播放。
2楼
admin 发表于: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编辑过]
共2 条记录, 每页显示 10 条, 页签: [1]

Copyright ©2002 - 2016 课外天地.Net
Powered By Dvbbs Version 8.3.0
Processed in .03101 s, 2 queries.