预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共15页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

P1105_6 publicclassTestSuper { publicstaticvoidmain(String[]args) { D200_Cardmy200=newD200_Card(); my200.balance=50.0; System.out.println("父类被隐藏的金额为:"+my200.getBalance()); if(my200.performDial()) System.out.println("子类的剩余金额为:"+my200.balance); } } abstractclassPhoneCard { doublebalance; abstractbooleanperformDial(); doublegetBalance() { returnbalance; } } abstractclassNumber_PhoneCardextendsPhoneCard { longcardNumber; intpassword; StringconnectNumber; booleanconnected; booleanperformConnection(longcn,intpw) { if(cn==cardNumber&&pw==password) { connected=true; returntrue; } else returnfalse; } } classD200_CardextendsNumber_PhoneCard { doubleadditoryFee; doublebalance; booleanperformDial() { if(balance>(0.5+additoryFee)) { balance-=(0.5+additoryFee); returntrue; } else returnfalse; } doublegetBalance() { returnsuper.balance; } } P121例5-10 publicclassTestOverride { publicstaticvoidmain(String[]args) { D200_Cardmy200=newD200_Card(12345678,1234,50.0,"200"); if(my200.performDial(1245678,1234)) System.out.println("拨打电话后剩余金额为:"+my200.getBalance()); if(my200.performDial()) System.out.println("拨打电话后剩余金额为:"+my200.getBalance()); } } abstractclassPhoneCard { doublebalance; abstractbooleanperformDial(); doublegetBalance() { returnbalance; } } abstractclassNumber_PhoneCardextendsPhoneCard { longcardNumber; intpassword; StringconnectNumber; booleanconnected; booleanperformConnection(longcn,intpw) { if(cn==cardNumber&&pw==password) { connected=true; returntrue; } else returnfalse; } } classD200_CardextendsNumber_PhoneCard { doubleadditoryFee; D200_Card(longcn,intpw,doubleb,Stringc) { cardNumber=cn; password=pw; balance=b; connectNumber=c; } booleanperformDial() { if(!connected) returnfalse; if(balance>(0.5+additoryFee)) { balance-=(0.5+additoryFee); returntrue; } else returnfalse; } boole