TestingDocs.com
    Software Testing website
    • Automation
      • Selenium
      • JBehave Framework
    • Tutorials
      • MySQL Tutorials
      • Testlink
      • Maven
      • Git
    • IDEs
      • IntelliJ IDEA
      • Eclipse
    • Flowcharts
      • Flowgorithm
      • Raptor
    • About

    Dart

    Dart Method Overriding

    Overview

    Let’s understand method overriding in Dart programming language. Method overriding is an important concept in OOPS. ( Object-Oriented Programming System)

    Method Overriding

    Method overriding is a concept where a subclass provides a specific implementation for a method that is already defined in its superclass. In other words, when we declare the same method in the child class, which is already defined in the superclass, this is known as method overriding. This OOPS concept allows a subclass to modify or extend the behavior of a method inherited from its superclass.

    The method overriding is a technique to achieve polymorphism. This technique is useful when we want a subclass object to give different results when it invokes the overridden method.

    Example

    Let’s understand the method overriding concept with an example.

    /*
    Method overriding demo example
    Dart Tutorials – www.TestingDocs.com
    */

    class Account {
    // Parent class overridden method
    void display()
    {
    print(“Bank account”);
    }
    }

    class SavingAccount extends Account {
    // Method Overriding in child class
    void display() {
    print(“Saving Account”);
    }
    }

     

    void main() {
    Account a = new Account();
    //This will invoke the parent class display method
    a.display();
    SavingAccount acc=new SavingAccount();
    //This will invoke the child class display method
    acc.display();
    }

     

    We have defined two classes; Account and SavingAccount. The SavingAccount subclass inherits the Account superclass.

    Dart method overriding

    The method display() is defined with the different implementations in both classes. The subclass overrides the display() method. It has its own definition of the display() method.

    When a method is called on an object, the actual implementation that gets executed is determined at runtime based on the object’s type, making it a powerful feature for creating flexible and extensible code.

    —

    Dart Tutorials

    Dart tutorial on this website can be found at:

    https://www.testingdocs.com/dart-tutorials-for-beginners/

    More information on Dart:

    https://dart.dev/

    Related Posts

    Dart Compilation Techniques

    Dart /

    Dart Compilation Techniques

    Dart String Interpolation

    Dart /

    Dart String Interpolation

    Dart Lists

    Dart /

    Dart Lists

    Dart /

    Dart String Methods

    Dart Print Expression

    Dart /

    Dart print() function

    ‹ Dart Static Method› Dart Abstract Classes

    Recent Posts

    • ChatGPT Subscription Plans
    • Stellar Converter for Database
    • Stellar Log Analyzer for MySQL
    • Stellar Repair for MySQL
    • ChatGPT Capabilities
    • How to secure your SQL Database: Tips and Tricks
    • ChatGPT4 Conversational AI Features
    • Shaping the Future of Development: Exploring Key Trends in Software Engineering
    • Improving Java Performance with Multithreading
    • Open-source Vector Databases

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com