There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
You can also find further discussion and get answers to your questions over in Language Help.
Agree with a comment or answer? Like () to up-vote the contribution!
STUCK OR BUG
I even checked the solution which is the same I tried. I tried a few different ways to put in the checkingAccount.java method like the straight forward return AB type or by using double interest = AB and return interest. But I keep getting red notice that I should use return AB which is what I did. And other ways means just BA the other way round.
So, I’m stuck here and cannot continue. Is it a bug or what?
For the first part, I got the answer but it wasnt considered correct until I tried getting the same answer using a different method. The answer it took was:
I tried about 3 or 4 different ways of writing this code and got the same answer but it took only this one as correct. Not sure why but thats okay. I deepend my understanding of the different ways the code can be written so its okay.
This should probably still be fixed by someone, though.
“return this.interestRate*this.balance;” does not pass even though it is totally valid
it needs to be "return this.interestRate * this.balance; " (notice the empty spaces)
Call the calculateNextMonthInterest() method on the accountOne instance.
It doesn’t say in which class I should make the method call, so I’m trying both:
public static void main(String[] args) {
accountOne.calculateNextMonthInterest();
}
If I write this in the CheckingAccount class, I get this error:
CheckingAccount.java:29: error: cannot find symbol
accountOne.calculateNextMonthInterest();
^
symbol: variable accountOne
location: class CheckingAccount
Alright, so the CheckingAccount class doesn’t have access to objects created in Bank.
If I make my method call inside of Bank, I get this error:
Bank.java:5: error: calculateNextMonthInterest() has private access in CheckingAccount
accountOne.calculateNextMonthInterest();
^
Yeah, of course - we made that method private on purpose.
So how is this supposed to work? Running accountOne.calculateNextMonthInterest() inside the CheckingAccount class does give me the check mark so I can continue, but I want to understand what’s going on:
Is it a bug?
If not, how do Java classes generally have knowledge of each other? Is it enough for the files to be located in the same directory?
And what about objects? Can they be created with an access modifier different from the one in their class definition?
If not, do they automatically inherit it from the class?
If they do inherit it, accountOne - created in Bank - should be accessible from inside the CheckingAccount class, since Bank is public.