Skip to content

Instantly share code, notes, and snippets.

@faizan1947
Last active July 15, 2022 05:56
Show Gist options
  • Save faizan1947/83dbbe47c828d211dde5adc0e10a518f to your computer and use it in GitHub Desktop.
Save faizan1947/83dbbe47c828d211dde5adc0e10a518f to your computer and use it in GitHub Desktop.
Dart Classes and Objects

Dart Classes and Objects

Created with <3 with dartpad.dev.

void main() {
//Create Objects from Human Class
//Create 1st Object
var newHuman = Human(age:0);
print(newHuman.age);
//Create second Object
final human2 = Human(age:23,eyes:2);
print(human2.eyes);
//Dot notation to use method
human2.talk('How are you?');
}
//Creating Class
class Human{
//Class properties
double? height;
int? age ;
int? eyes;
//This is constructor
Human({ required this.age,this.eyes,this.height});
//Let's create method
//Function inside class called method
void talk(String whatToSay){
print(whatToSay);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment