Created with <3 with dartpad.dev.
Last active
July 15, 2022 05:56
-
-
Save faizan1947/83dbbe47c828d211dde5adc0e10a518f to your computer and use it in GitHub Desktop.
Dart Classes and Objects
This file contains 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
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