Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build an Interactive Story App (Retired) The Model-View-Controller Pattern Adding Custom Constructors

peter keves
peter keves
6,854 Points

new Choice

at 2:51 we wrote new Choice I don't quite understand why can somebody help me ?

1 Answer

When 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
peter keves
6,854 Points

Thanks for quick reply :) ! it helped me to understand it