Skip to content

Commit

Permalink
Getters and Setters along with Private Instance variable
Browse files Browse the repository at this point in the history
  • Loading branch information
smartherd committed Jul 2, 2018
1 parent bd8feb4 commit da65696
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions 21_getters_setters.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

// Objectives
// 1. Default Getter and Setter
// 2. Custom Getter and Setter
// 3. Private Instance Variable

void main() {

var student = Student();
student.name = "Peter"; // Calling default Setter to set value
print(student.name); // Calling default Getter to get value

student.percentage = 438.0; // Calling Custom Setter to set value
print(student.percentage); // Calling Custom Getter to get value
}

class Student {

String name; // Instance Variable with default Getter and Setter

double _percent; // Private Instance Variable for its own library

// Instance variable with Custom Setter
void set percentage(double marksSecured) => _percent = (marksSecured / 500) * 100;
// Instance variable with Custom Getter
double get percentage => _percent;
}

0 comments on commit da65696

Please sign in to comment.