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 (Retired) Harnessing the Power of Objects Method Signatures

Alex Popian
Alex Popian
977 Points

Am I getting this right?

So let me get this straight; when we call the first drive method it takes an int and the int is represented by the number of laps. Each lap takes off one BarCount. 2 laps = 2 bars. So when we call the second drive method, this time we call it drive() since it's not using any parameters. After, inside the new drive method we call the old one but we specify the number of laps by saying drive(1) which is basically like saying drive(int 1) since 1 replaces the laps? I am having a hard time with these things and I hope someone can tell me that I am actually getting something. Thanks for your time!

2 Answers

shekhar bhardwaj
seal-mask
.a{fill-rule:evenodd;}techdegree
shekhar bhardwaj
Full Stack JavaScript Techdegree Student 12,373 Points

You have to overload the method : for example argument signature of this method is not same as other drive method which expects integer.

 public void drive(int laps) {
    // Other driving code omitted for clarity purposes
    mBarsCount -= laps;
  }

   public void drive(){
   //perform your challenge here this an overloaded method.
   }
Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Hey Alex, that logic is correct. Method overloading can be used to "default" parameters, just like this.

Can't tell if you still have a question, but happy to answer if you do ;)

Alex Popian
Alex Popian
977 Points

@Craig Dennis Thanks for answering me, you're an awesome professor. The only other question I would have is if I'm having trouble with words like let's say: public, private, void, etc. How should I go about learning them? Should I just keep going with the coursesand have them sink in or memorise them before advancing any further in java? Once again thanks for your time :)