Created
          April 20, 2020 23:56 
        
      - 
      
- 
        Save kharioki/889ae220d13e5de8c794c87dd580145b to your computer and use it in GitHub Desktop. 
    class constructors in dart
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // Class constructors | |
| void main() { | |
| Human june = Human(165, 120); | |
| print(june.height); | |
| print(june.weight); | |
| Human tony = Human(170, 140); | |
| print(tony.height); | |
| print(tony.weight); | |
| } | |
| class Human { | |
| // property | |
| double height; | |
| double weight; | |
| int age = 24; | |
| // constructor | |
| // Human({double height, double weight}) { | |
| // this.height = height; | |
| // this.weight = weight; | |
| // } | |
| Human(this.height, this.weight); | |
| // method | |
| void grow(int numberOfYears) { | |
| age = age + numberOfYears; | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment