Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

A method inside a method?

Hello, I have this doubt in the "Incrementing and Decrementing" chapter of Java Objects:

public boolean dispense() {

boolean wasDispensed = false;
if (!isEmpty()) {
  pezCount-- ;
  wasDispensed = true;

}
return wasDispensed;

}

  • In the code above, the isEmpty() method doesn't have an object calling for it... Can someone explain how does it work? Regards.

isEmpty() is just a method invocation. You use dot notation when the method is on an object or a class (eg. object.doSomething() or Class.doSomethingStatic()). However, if the method is being called on the current object, then you can just call it.

Thanks :)