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 trialpeter keves
6,854 Pointsnew Choice
at 2:51 we wrote new Choice I don't quite understand why can somebody help me ?
1 Answer
Hao Tran
17,264 PointsWhen you use "new", you are creating a new instance of the object (in this case, a Choice object).
This is where the custom constructors (of the lesson) come into play. When you create a new instance of an object, the system will call the constructor method to know how to create the object. In this case, the constructor for a Choice object is the following:
public Choice(String text, int nextPage) {
mText = text;
mNextPage = nextPage;
}
So when he creates a Choice object (via the new statement), he provides data to be included in the object (the text and the ID for the next page).
peter keves
6,854 Pointspeter keves
6,854 PointsThanks for quick reply :) ! it helped me to understand it