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 Android Lists and Adapters (2015) Using Parcelable Data Retrieving Parcelable Data

How override method work in android !!

some method we do not call them in android , like method we override from another class, how these method calling ?? example:

public static final Creator<Day> CREATOR = new Creator<Day>() {
        @Override
        public Day createFromParcel(Parcel source) {
            return new Day(source);
        }

        @Override
        public Day[] newArray(int size) {
            return new Day[size];
        }
    };   ```

3 Answers

What I was trying to say is that you are implementing a parcelable interface and to use this interface you have to implement its required method such as writeToParcel() and others, so I think when you create a new object from the class in your case DAY class, the methods from the parcelable interface are invoked automatically to create a parcelable object of this class.

I recommend you to check topics like Interface, inheritance, method overriding and overloading and keep going deep inside java concepts so you will get a better understanding of how the things works in Android.

i search in many website for the answer, i found these method implements inside android system and android deal with these method automatically when application is running

Method overriding is used to provide specific implementation of a method that is already provided by its super class, so when one of its ancestors calls that method it runs the current overrode method you coded in your class.

In this case you are implementing a Parcelable interface and you have to implement it's method, so by adding the @override annotation you will "ask" the compiler to verify if the method actually overrides a super class or interface method or not. This way, if you make a common mistake of misspelling a method name or not correctly matching the parameters the compiler will tell you.

I hope I answered it!

<p>thanks for your answer</p> <p>but the main questions is: it implements the override method from super class and give method structure i need ,and cod inside this method will calling automatically without writing the name of this overriding method to call it in somewhere , do not understand how these work ??how compiler calling these method ??</p>

Check this link you, it might help you!

http://javarevisited.blogspot.ca/2012/03/what-is-static-and-dynamic-binding-in.html

In the case of your code you are implementing required methods from a Parcelable interface, so I might be wrong but I think the methods of the interface are executed when you instantiate the class, you don't need to explicitly call them

<p> thank you i read the link you posted its help me ,you say can call override method just if create new instance from its subclass? how these work?, I do not think this is true, unless override method called in constructor of subclass</p>