Test Driven Development By Example Query
"Aaron Carey [email protected] [testdrivendevelopment]" <[email protected]> Tue, 11 Nov 2014 16:25:47 +0000
| Newsgroups | gmane.comp.programming.test-driven-development |
|---|---|
| Message-ID | <CAGAUafAZ1ejhpk26TtymDcG_3o5LFhgzG_WD2OeQyG-rJXgCug@mail.gmail.com> |
Hi,
I'm sorry this may be a rather stupid question, but it's been bugging me as
I'm reading through Kent Beck's book 'Test-Driven Development By Example'
I think it might be my understanding of Java (I have a C++/Python
background) but I was really hoping someone could clear something up!
This happens a few times in the book so far, but here's an example:
on Page 24, there's a Franc class which defines equals and sets the amount
variable as a private int. Within the equals method a Franc object passed
into the method has the amount variable queried. How does this work? I
thought private variables couldn't be accessed outside of the object, but
here you query it from another object? Is there some sort of friend class
behaviour?
Thanks so much for your help!
class Franc {
private int amount;
Franc(int amount) {
this.amount= amount;
}
public boolean equals(Object object) {
Franc franc= (Franc) object;
return amount == franc.amount;
}
}