Dart Inheritance : Overriding parent Method | Method Overriding

Dart Inheritance : Overriding parent Method | Method Overriding

·

1 min read

Method Overriding :

  • When we declare the same method in the subclass, which is previously defined

    in the superclass is known as the method overriding.

  • he subclass can define the same method by providing its own implementation,

    which is already exists in the superclass.

  • The method in the superclass is called method overridden, and methods in the

    subclass is called method overriding.

Example

  •   class Human {
    
        void run() {
          print("Human is running");
        }
      }
    
      class Man extends Human {
    
        @override
        void run() {
          print("Boy is running");
        }
      }
    
      void main() {
        Man m = Man();
    
        m.run();
      }
    
  •   Boy is running
    
      Exited.