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 trialKeivan Norouzi
4,513 PointsWhy don't we need "super" keyword before startActivity method in our startStory method?
I wonder how the program still works, we use the method startActivity that belongs to the super(parent class) which in this case is Activity class, without writing "super" keyword before it !?!
1 Answer
Ben Deitch
Treehouse TeacherWe don't need the super keyword before startActivity because MainActivity IS an Activity. When we override a function the underlying function is entirely replaced. That's why we call super so frequently in Android; we want to call the parent's method as well as the child's. Here's an example:
public class Cake {
public void onCreate() {
mixIngredients();
putInPan();
bakeACake();
}
public void notifyCakeFinished() {
callClient();
}
}
public class WeddingCake extends Cake {
@Override
public void onCreate() {
super.onCreate();
decorateCake();
notifyCakeFinished();
}
}
Keivan Norouzi
4,513 PointsKeivan Norouzi
4,513 PointsThank you so much, it helped me a lot to understand it. :)