答案:A
第六行:System.out.println(mc1.getValue());
第七行:System.out.println(mc2.getValue());
package org.jsoft.extend;
public class Account {
private long id;
private double balance;
private String passworld;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public String getPassworld() {//密码get方法返回null
return null;
}
public void setPassworld(String passworld) {//set方法只有密码长度为6时才能传参
if(passworld.length()==6){
this.passworld = passworld;
}
}
public void show(){
System.out.println(passworld);
}
}
package org.jsoft.extend;
class SavingAccount extends Account{
private double interestRate;
public double getInterestRate() {
return interestRate;
}
public void setInterestRate(double interestRate) {//set方法利率大于0小于0.1才能传参
if(interestRate>0&&interestRate<0.1) {
this.interestRate = interestRate;
}
}
}
package org.jsoft.extend;
class CreditAccount extends Account{
private double cerditLine;
public double getCerditLine() {
return cerditLine;
}
public void setCerditLine(double cerditLine) {
this.cerditLine = cerditLine;
}
}
package org.jsoft.extend;
public class Test {
public static void main(String[] args) {
Account a = new Account();
a.setPassworld("1234567");//测试密码长度不正确
System.out.println(a.getPassworld());//测试get密码返回null
a.show();
SavingAccount s = new SavingAccount();
s.setInterestRate(0.2);//测试概率不正确
System.out.println(s.getInterestRate());
}
}