Instance Variables & Instance Methods in Dart
Jinali Ghoghari
1 min read
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
}
}
0
Subscribe to my newsletter
Read articles from Jinali Ghoghari directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by