Conversation


Your input fuels progress! Share your tips or experiences on prioritizing mental wellness at work. Let's inspire change together!

Join the discussion and share your insights now!

Comments 0


advertisement

this and super keyword in Dart Programming

this and super keyword


this Keyword

this keyword is included when parameters and attributes of the same name as class attributes are used. It refers to the current class object and this keyword removes ambiguity which is generated while declaring the same name of parameters and attributes.

void main()
{
student std = new student('99');
}
class student
{
 var stdid;
 student(var stdid)
 {
   this.stdid = stdid;
   print("Dart this keyword Example");
   print("Student ID is: ${stdid}");
 }
}



super Keyword

super keyword is used to refer to the parent class object. Methods and properties of the parent class can be called with the help of a super keyword. It also removes ambiguity between parent class methods and child classes that have the same method name and are called through objects.

class parentclass{
 String name = "Example of super keyword";
}
class subclass extends parentclass{
 String name = "TEXVN";
void showMessage(){
  print(super.name);
  print("$name has ${name.length} letters.");
  }
}
void main(){
 subclass myclass = new subclass();
 myclass.showMessage();
}

Dart this keyword super keyword dart programming dart coding

advertisement