0
0
Fluttermobile~10 mins

Classes and objects in Flutter - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a class named Person.

Flutter
class [1] {
  String name;
  Person(this.name);
}
Drag options to blanks, or click blank then click option'
AAnimal
BPerson
CCar
DWidget
Attempts:
3 left
💡 Hint
Common Mistakes
Using a class name that does not match the constructor.
Choosing unrelated class names.
2fill in blank
medium

Complete the code to create an object of the Person class.

Flutter
var person = [1]('Alice');
Drag options to blanks, or click blank then click option'
AAnimal
BWidget
CPerson
DCar
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong class name to create the object.
Forgetting to add parentheses.
3fill in blank
hard

Fix the error in the method to return the person's name.

Flutter
class Person {
  String name;
  Person(this.name);

  String getName() {
    return [1];
  }
}
Drag options to blanks, or click blank then click option'
Athis.name
Bname()
CgetName
DPerson.name
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call name as a function.
Using class name to access instance variable.
4fill in blank
hard

Fill both blanks to add an age property and initialize it in the constructor.

Flutter
class Person {
  String name;
  int [1];

  Person(this.name, this.[2]);
}
Drag options to blanks, or click blank then click option'
Aage
Bheight
Cweight
Dscore
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for property and constructor parameter.
Choosing unrelated property names.
5fill in blank
hard

Fill all three blanks to create a method that returns a greeting with the person's name and age.

Flutter
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].';
  }
}
Drag options to blanks, or click blank then click option'
Aname
Bage
Cold
Dyears
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names.
Forgetting to use the word 'old' in the sentence.