Dart : Super Keyword

Dart : Super Keyword

ยท

1 min read

  • In dart there are various keyword , and each keyword has their own meaning , The same for " super " keyword.

    • The super keyword is used to access the parent class members.

    • The super keyword is used to call the method of the parent class.

  • First , we create two class one of parent class second one is child with which extend the parent class and his property. while both the function name is the same.

  • For ,this we write " super.ios " in child class which means time of the output it will call parent ios function then call own class function.

void main()
{
  var mobile = android(); // Create the object
  mobile..ios();
}
// parent class
class apple  
{
   void ios()
   {
    print("This is parent class of Apple.");
   }
}

//child class
class android extends apple
{

   void ios()
   {
    super.ios(); // Calling the show method of the parent class
    print("This is copy of child class IOS ");

   }
}
  • we can see that first statement is on apple class and second statement is in android class.

ย