How to create Method in DART
In this article, I am going to explain Dart method.
Methods in Dart
An orderly process is called method. Dart have two method-
- Instance method
Instance methods on objects can access instance variable
Example of instance method
class InstanceMet{
PlzCallMe(){
print("I am a Instance Method");
}
}
void main() {
InstanceMet obj = new InstanceMet();
obj.PlzCallMe();
}
|
Output:
- Static method
Static method resolved at compile time. In static method you can only use static data member, and there is a no need to create a object; you can call static method by it's class name.
Example of static method
class StaticMeth{
static int i=5;
static int Method(){
print("Static method value is ${i}");
}
}
void main() {
StaticMeth.Method(); // calling of static method
}
|
Output:
Got a programming related question? You may want to post your question here