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 trialfadi badir
Courses Plus Student 1,441 Pointsi 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
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
Treehouse TeacherHi 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!
Alex Bratkovskij
5,329 PointsHello fadi,
You forgot to declare acces modfier for your class (private, public, protected) ;)
Good luck ;)
-Alex
fadi badir
Courses Plus Student 1,441 Pointsyou mean the GoKart class?
andren
28,558 PointsAlex 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
5,329 PointsThanks 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!