0Pricing
Dart Academy · Lesson

Instance Methods and this

Add behavior that acts on instance data.

Adding Behavior

Fields store data, but a class can also do things. A function defined inside a class is called an instance method.

Your First Method

Write a method just like a function, but inside the class body. It can read and use the object's own fields directly.

class Dog {
  String name = "Rex";
  void bark() {
    print("Woof!");
  }
}

All lessons in this course

  1. Defining a Class With Fields
  2. Instance Methods and this
  3. Getters and Setters
  4. Static Members and Class Constants
← Back to Dart Academy