Classes and Objects in Dart

 Classes and Objects in Dart


Dart is an object-oriented language, which means that it supports classes and objects. Classes are used to define the properties and behaviors of an object, and objects are instances of a class.


class Person {

  String name;

  int age;


  Person(this.name, this.age);


  void sayHello() {

    print('Hello, my name is $name');

  }

}


void main() {

  var person = Person('John Doe', 25);

  person.sayHello();

}

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...