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
- Defining a Class With Fields
- Instance Methods and this
- Getters and Setters
- Static Members and Class Constants