Skip to content

Instantly share code, notes, and snippets.

@sdkdeepa
Last active March 20, 2023 07:05
Show Gist options
  • Save sdkdeepa/eaa2522adeeeeb533a79cc7a47b2aaa5 to your computer and use it in GitHub Desktop.
Save sdkdeepa/eaa2522adeeeeb533a79cc7a47b2aaa5 to your computer and use it in GitHub Desktop.
Classes in Dart

Classes in Dart

// 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