Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java balance在SavingsAccount1和won'中拥有私人访问权限;我不允许在FlexibleSavingsAccount1中访问它_Java_Inheritance_Polymorphism_Private - Fatal编程技术网

Java balance在SavingsAccount1和won'中拥有私人访问权限;我不允许在FlexibleSavingsAccount1中访问它

Java balance在SavingsAccount1和won'中拥有私人访问权限;我不允许在FlexibleSavingsAccount1中访问它,java,inheritance,polymorphism,private,Java,Inheritance,Polymorphism,Private,保存帐户1,不让我访问它的信息 public abstract class SavingsAccount1 //public static double annualInterestRate; private double balance; private final int ACCOUNT_NUMBER;{ public SavingsAccount1(){ this.balance = 0.0; this.ACCOUNT_NUMBER =0; } public Saving

保存帐户1,不让我访问它的信息

public abstract class SavingsAccount1
//public static double annualInterestRate;
private double balance;
private final int ACCOUNT_NUMBER;{

public SavingsAccount1(){
    this.balance = 0.0;
    this.ACCOUNT_NUMBER =0;
}
public SavingsAccount1(int ACCOUNT_NUMBER, double balance)
{
this.balance = balance;
this.ACCOUNT_NUMBER = ACCOUNT_NUMBER;
}
public abstract void addMonthlyInterest();

public double getBalance()
{   return balance;
}
public void setBalance(double balance){
this.balance = balance; 
}

public int getAccount_Number()
{
return ACCOUNT_NUMBER;
}

}

public class FlexibleSavingsAccount1 extends SavingsAccount1{

//private double addInterest;
public static double annualInterestRate;

public FlexibleSavingsAccount1 (int ACCOUNT_NUMBER, double balance){

    super(ACCOUNT_NUMBER, balance);

    //this.annualInterestRate = annualInterestRate;
    //this.balance = balance;
    //this.addInterest = addInterest;

}//end of 

In this method I am trying to override, it says that balance has private Access in 
}//弹性储蓄账户结束

我已经尝试了我能想到的一切,所以如果代码看起来不好,我会提前道歉。我已经改变了太多,我甚至不知道在这一点上做什么。你们能提供的任何帮助都太棒了

正确。改变这个

@Override public void addMonthlyInterest(){

    balance =balance +(balance * annualInterestRate / 12);
}


这样子类就可以直接访问它。或者,您可以使用
setBalance(double)
getBalance()

声明为私有的方法和变量只能在声明的类本身中访问

受保护的访问修饰符允许您访问同一类及其所有子类中的变量

private double balance;
protected double balance;