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.

Define Multiple Constructors

This video was last updated on Jun 28 2022

Learn how to define multiple constructors in your classes using something known as named constructors.

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.

A few episodes back, we created RPGCharacter class.

class User {
    int id;
    String name;

    User(this.id, this.name);
}
User.anonymous()
User.anonymous() : id = 0, name = 'anonymous';
var user1 = User(42, 'Ray');
var user2 = User.anonymous();
print(user1.name);
print(user2.name);

Reviews

Comments