How to use getters and setters method in DART

In this article, i am going to explain use of get and set keyword.
  • 6708

Getters and Setters method in Google Dart language

Dart getters and setters method provide read and write functionality. Getter and setter method using the get and set keyword. The get keyword is used for reading a value and set keyword is used for writing a value.

Example of Getters and setters method

class GetnSetMet{

  String f_name,l_name;

  String get firstName() => f_name;

  set firstName(String value) => f_name = value;

  String get lastName() => l_name;

  set lastName(String value) => l_name = value;

  String get FullName() => firstName.concat(lastName);

 

}

void main() {

  var obj = new GetnSetMet();

  obj.firstName="Google";

  obj.lastName="Dart!";

  print(obj.FullName);
}


Output:

 gettersetter.jpg

Ask Your Question 
 
Got a programming related question? You may want to post your question here
 
© 2019 DotNetHeaven. All rights reserved.