Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello,
I have just started taking Java (programming III/IV) at my high school, and was wondering if any of you can give me a better explanation of the following question, than what my teacher had told me.The question is... What does the following method do? Give an example of how you can call the method.
public class BankAccount
{
public void mystery(BankAccount that, double amount)
{
this.balance=this.balance-amount;
that.balance=that.balance+amount;
}
...// Other bank account methods
}where does 'amount' come from, and what does it mean when its declared inside the implicit parameter of public void mystery? What has me really confused is what is going on with both 'that' and 'amount', why they are declared in the implicit parameter.
If you can provide me with a better explanation, I will certainly be a happier programmer, and I wont worry about it the next few days at school and work. Thanks in advance! (P.S. - if you have any questions relating to computer hardware/software troubleshooting, ask away, we can trade off this way! Im not nearly as good at programming as I am with computer repair!)
Geek Squad CIA
CompTIA A+ Certified
CST Certified
Certs-in-Progress:
CCNA, CompTIA Network+

I bet you miss the instance variable.
It should be:
public class BankAccount
{
private double balance;public void mystery(BankAccount that, double amount)
{
this.balance=this.balance-amount;
that.balance=that.balance+amount;
}
...// Other bank account methods
}In the example, you are right, the "that" paramater is not used. If you get the code from example, than I would say it is a bad example.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |