Last active
March 20, 2023 07:05
-
-
Save sdkdeepa/eaa2522adeeeeb533a79cc7a47b2aaa5 to your computer and use it in GitHub Desktop.
Classes in Dart
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
// Classes are blueprint for an object | |
// user object describried by using properties and methods | |
void main() { | |
// instantiaing a class with the User object | |
User userOne = User(); | |
print(userOne.username); | |
print(userOne.age); | |
userOne.login(); | |
print("------------------------------------------"); | |
print("Will create the same user with the name for userTwo"); | |
User userTwo = User(); | |
print(userTwo.username); | |
print(userTwo.age); | |
} | |
// creating a class with User object with properties such as name and age and | |
// with a login() | |
class User{ | |
String username = 'Andy'; | |
int age = 25; | |
// login function inside of the User object | |
void login() { | |
print('user is logged in'); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment