Computing.Net > Forums > Programming > Java Method Question

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Java Method Question

Reply to Message Icon

Name: 2FAST4U (by TheWaNGeR)
Date: September 5, 2006 at 14:22:52 Pacific
OS: Windows XP Professional 5
CPU/Ram: Athlon64 3500+ Venice Cor
Product: Self
Comment:

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+



Sponsored Link
Ads by Google

Response Number 1
Name: Sanjaya Sugiarto (by Sanjaya)
Date: September 10, 2006 at 08:45:32 Pacific
Reply:

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.


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Java Method Question

java Method class www.computing.net/answers/programming/java-method-class/9980.html

Passing argument for Java method. www.computing.net/answers/programming/passing-argument-for-java-method/10374.html

implementation of java methods in C www.computing.net/answers/programming/implementation-of-java-methods-in-c/17528.html