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 trial

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.