Complete the code to define a class named Person.
class [1] { String name; Person(this.name); }
The class name should be Person to match the constructor and represent a person.
Complete the code to create an object of the Person class.
var person = [1]('Alice');
To create an object, use the class name Person followed by parentheses with arguments.
Fix the error in the method to return the person's name.
class Person { String name; Person(this.name); String getName() { return [1]; } }
Use this.name or simply name to access the instance variable inside the class.
Fill both blanks to add an age property and initialize it in the constructor.
class Person { String name; int [1]; Person(this.name, this.[2]); }
The property and constructor parameter should both be named age to store the person's age.
Fill all three blanks to create a method that returns a greeting with the person's name and age.
class Person { String name; int age; Person(this.name, this.age); String greet() { return 'Hello, my name is $[1] and I am $[2] years [3].'; } }
The method uses name and age variables and the word old to form the greeting sentence.