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

    Dart

    Define Dart Class

    Overview

    Let’s learn how to define Dart class in this tutorial. We can define a class in Dart programming language using the class keyword.

    Define Dart Class

    The general syntax of the Dart class is as follows:

    class class_name {

    <fields>

    <getters/setters>

    <constructor>

    <methods>

    }

     

    The class keyword is followed by the class name defined by the user. The class definition is provided inside the curly braces. A Dart class can consist of fields, constructors, getters, setters, and methods.

    Example

    /*
    Define a Dart class
    Dart Tutorials – www.TestingDocs.com
    */

    void main() {
    var book =new Book();
    book.title=”The Old man and the Sea”;
    book.author=”Ernest Hemingway”;
    book.pages=98;
    book.price=90;
    //Accessing class Function
    book.displayBookInfo();

    }

    //Define a class Book

    class Book {
    var title;
    var author;
    var pages;
    var price;

    // Class Function
    displayBookInfo() {
    print(“Book Name is : ${title}”);
    print(“Book Author is :${author}”);
    print(“Number of Pages: ${pages}”);
    print(“Book Price is: ${price}”);
    }
    }

    Explanation

    In this example, we have declared a class called Book. The Book class has the following fields

    title
    author
    pages
    price

    The displayBookInfo() is a class function that prints the fields of the Book class.

    Define Dart Class

    —

    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

    ‹ Calling a Dart Function› Dart static keyword

    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