Last active
March 20, 2023 07:04
-
-
Save sdkdeepa/86380ff3d924ca3f41fb57f8dc55183e to your computer and use it in GitHub Desktop.
Classes and 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
// Classes are blueprint for an object | |
// user object describried by using properties and methods | |
void main() { | |
// instantiaing a class with the User object | |
print("******************************"); | |
print("To avoid hard codes values inside the class, created a constructor class."); | |
print("Constructor is a spl class"); | |
print("******************************"); | |
print(''); | |
User userOne = User('Andy',30); | |
print(userOne.username); | |
print(userOne.age); | |
userOne.login(); | |
print(''); | |
User userTwo = User('Deepa', 35); | |
print(userTwo.username); | |
print(userTwo.age); | |
userTwo.login(); | |
} | |
// creating a class with User object with properties such as name and age and | |
// with a login() | |
class User{ | |
String username ; | |
int age; | |
User(this.username,this.age); | |
// 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