Instance Variables & Instance Methods in Dart

Instance Variables & Instance Methods in Dart

Instance Variable:

  • when we declare variables within a class, they are commonly referred to as "instance variables" or "member variables."

Instance Method:

  • When we declare methods within a class, they are commonly referred to as "instance methods".


Example:

void main() {
    var obj = Student();
    obj.display();    
}
class Student{
//Instance Variables
var name = 'Jinali';
var age = '21';

//Instance Method
void display() {
    print('Name = $name'); //Output: Jinali
    print('Age = $age'); //Output: 21
    }
}