If private member variables can be inherited from the base class?I read some books describes as NO,they thought one class should be inherited all methods and attributes from the base class,otherwise there is an entire duplication from the base class in the derived class.I think the derived class has a copy of based class,it just can not be accessed when the base class member variables specified as private?
public abstract class PhoneCard {
private Long id;
private String password;
private Double balance;
private String digits;
public PhoneCard() {}
public PhoneCard(Long id,String password,Double balance,String digits) {
this.id = id;
this.password = password;
this.balance = balance;
this.digits = digits;
}
//...
}
public class TwoHundredCard extends PhoneCard {
public TwoHundredCard() {}
public TwoHundredCard(Long id,String password,Double balance,String digits) {
super(id,password,balance,digits);
//methods was inherited from base type,but the private fields was not
}
//...
@Override
public void priceCount() {
System.out.print("connection successful established ...");
this.balance -= 0.5;//balance can't be accessed,
//but there is a whole copy of PhoneCard
}
}
yours friend!