Get immediate access to this and over 1,500+ other videos and books.

Boost your skills with a raywenderlich.com Beginner subscription. With over 60+ video courses and our core foundational programming books bundled in one subscription, it’s simply the best investment you can make in your development career.

Challenge: Override a Method

This video was last updated on Jun 28 2022

Put your method overriding skills to the test in this episode’s challenge.

Contributors

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a raywenderlich.com Professional subscription.

So now you have a good idea about subclasses and then how to override methods, it’s time to put your newfound skills to the test. I want you to create a Profile class. It should contain a user name which is a string, a user id which is an int, and interests with is a list of strings.

class Profile {

}
int userId;
String username;
List<String> interests;
Profile(this.username) : userId = 0, interests = [];
@override
String toString() => 'userId: $userId, username: $username, interests: $interests';
var profile = Profile('Larry');
profile.userId = 100;
profile.interests.add('swimming');
profile.interests.add('dancing');
profile.interests.add('coding');
print(profile);

Reviews

Comments