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 trialKay Larry
213 Pointsandroid help
pls help
public class Spaceship {
public String shipType;
public String getShipType() {
return shipType;
}
public void setShipType(String shipType) {
this.shipType = shipType;
}
public void Spaceship(){
setShipType("SHUTTLE");
}
}
1 Answer
Linda de Haan
12,413 PointsPlease state a question or explain the problem you are facing when you post to the forum. We can't help you if you just write "pls help".
Looking at your code I do see an error. It looks like in the last code block you're trying to set the ShipType to "SHUTTLE". This is how you do it:
public class Spaceship {
public String shipType;
// Set the shipType inside the constructor
public Spaceship() {
shipType = "SHUTTLE";
}
public String getShipType() {
return shipType;
}
public void setShipType(String shipType) {
this.shipType = shipType;
}
}
A constructor doesn't have a return type, so remove the void. Set the ShipType inside the constructor and not inside the parantheses. Also it's best practice to write the constructor at the top of your class, above all your methods and under the member variables.