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

Damian Adams
Damian Adams
21,351 Points

Why did we initialize the Choice fields to null in our custom Page constructor?

Near the end of the video Ben Jakuben goes on ahead to create a custom constructor to cover the last two Page initializations (5 and 6) of our Page array in our Story class. However, when we go on ahead to create this custom constructor, we initialize the two Choice variables to null:

public Page(int imageId, String text) {
        mImageId = imageId;
        mText = text;
        mChoice1 = null;
        mChoice2 = null;
        mIsFinal = true;
    }

Why is this necessary? I thought by default all objects/reference types are initialized to null values? See here: http://stackoverflow.com/questions/16699593/uninitialized-object-vs-object-initialized-to-null

Is this not unnecessary code? Would it make any difference to leave them "uninitialized"? Should they not posses the same null values?

Thanks in advance.