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 Increment and Decrement

i can't understand when i create a method and it says that it shouldn't return any and the type must be void!!

the challenge says that i need to create a method and it should return nothing when i create the method is says i should return with the type "void" when i do it says that number one no longer passing

GoKart.java
class GoKart {
  public static final int MAX_BARS = 8;
  private String color;
  private int barCount;
  private int lapsDriven ;

  public  boolean drive(){
    void return ;

  }










  public GoKart(String color) {
    this.color = color;
  }

  public String getColor() {
    return color;
  }

  public void charge() {
    barCount = MAX_BARS;
  }

  public boolean isBatteryEmpty() {
    return barCount == 0;
  }

  public boolean isFullyCharged() {
    return MAX_BARS == barCount;
  }
}

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You've typed void return. But you've set up your drive method to return a boolean. When declaring a function we first say the access modifier (public private etc). Then the return type, then the name of the function, and finally the parameter list.

So the definition of your method should look like

public void drive() {

}

This declares a method named drive with public access that returns nothing. Hope this helps! :sparkles:

Alex Bratkovskij
Alex Bratkovskij
5,329 Points

Hello fadi,

You forgot to declare acces modfier for your class (private, public, protected) ;)

Good luck ;)

-Alex

you mean the GoKart class?

andren
andren
28,558 Points

Alex Bratkovskij: It is not invalid to not declare an access modifier when creating a class. Doing so will just result in the class having the default access modifier level which is package-private. Meaning that it can only be accessed by other classes within the package it is a part of.

Alex Bratkovskij
Alex Bratkovskij
5,329 Points

Thanks andren I did not know that... (I red it somewhere but since I always declare access modifier I totally forgot) Thanks, I will write it down!