This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
The method declarations such as "public SavingsAcc2 addInterest(double interest)" indicate a type of "SavingsAcc2" is expected to be returned. The return statement is not returning anything.
Not sure what the intent is. If you do not want anything returned, you can delcare void as the return type "public void addInterest(double interest)". Otherwise, you'll need to return an instance of SavingsAcc2 as it is currently coded.
specify a return type "SavingsAcc2" but don't return a value of that type. In fact, they don't return a value at all of any type. Either change the return type to void, meaning you won't be returning anything, or provide a value of type SavingsAcc2 in your return statement.
- indent your code properly.
- a method will return when it is done, a "return;" is not required.
- I don't know what you mean by "so that I can put together multiple methods in a single line." Can you show an example?
Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Thanks for the comments. I did not understand what what was envisioned either. Returning 'this' would solve the compile errors. While this would be 'legal' in a java sense, I question the value of coding methods to operate this way as you are limiting yourself to be able to do it only with methods which do not return anything.
If there is a need for the user to perform many method calls at once, perhaps a helper method which invokes them all would be a better approach. I digress from the main question a little, sorry!!