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: Define a Constructor

This video was last updated on Jun 28 2022

Once you have a good idea on how to create a constructor, you’ll put your knowledge to the test by creating a very specific constructor.

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.

With your new knowledge of constructors, I think it’s time to give you another challenge. In your first challenge, you created an RPG character class. Your going to do it again, only this, I want to create a constructor that takes in the character’s name and the three stats.

class RPGCharacter {

}
String name;
int strength;
int dexterity; 
int constitution;
RPGCharacter(this.name, this.strength, this.dexterity, this.constitution);
  RPGCharacter(this.name, 
               this.strength, 
               this.dexterity, 
               this.constitution);
void printStats() {
    print('$name has $strength strength, $dexterity dexterity, and $constitution constitution');
}
    print('$name has $strength strength, '
          '$dexterity dexterity, and $constitution'
          ' constitution.');
 var fizBoz = RPGCharacter('Fizboz', 13, 10, 17);
 fizBoz.printStats();
RPGCharacter(this.name, { this.strength = 0, this.dexterity = 0, this.constitution = 0 });
var fizBoz = RPGCharacter('Fizboz', strength: 13, dexterity: 10, constitution: 17);

Reviews

Comments