Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //can have code outside the class
- void main() {
- Person person1 = new Person('A', 100000.0);
- Person person2 = new Person('B', 110000.0, empType: EmployeeType.CONTRACT);
- print(person1.salary);
- person1.giveRaise(7);
- print(person1);
- }
- //use lowerCamelCase for constant variables.
- //Begin global constant names with prefix "k"
- const int kConversionRate = 65;
- double getINRSalary(double salary) => salary * kConversionRate;
- enum EmployeeType { FTE, CONTRACT, INTERN }
- class Person {
- String name;
- double _salary;
- EmployeeType empType;
- //getter
- double get salary => _salary; // this makes _salary read only
- Person(this.name, this._salary, {this.empType = EmployeeType.FTE});
- void giveRaise(int percent) {
- _salary *= (100 + percent) / 100;
- }
- @override
- String toString() => 'Employee $name has salary $_salary';
- }
Add Comment
Please, Sign In to add comment