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 Java Objects Harnessing the Power of Objects Overload Methods

On Object, how do I call a new method called drive that pass and int of 1 by default?

Do I assign assign drive = 1 in the new method body?

1 Answer

Emmanuel C
Emmanuel C
10,636 Points

Hey Biswas,

Once youve updated the drive method to take a parameter of how many laps should be driven, like so ...

public void drive(int laps) {
    lapsDriven += laps;
    barCount -= laps;
}

It asked to create another method called drive with no parameters, but it calls the drive method with the parameter and has a 1 passed in. So...

public void drive(){
    drive(1);
}