forked from smartherd/DartTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Class, Objects, Instance Variable, Functions and Reference Variables
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
void main() { | ||
|
||
var student1 = Student(); // One Object, student1 is reference variable | ||
student1.id = 23; | ||
student1.name = "Peter"; | ||
print("${student1.id} and ${student1.name}"); | ||
|
||
student1.study(); | ||
student1.sleep(); | ||
|
||
var student2 = Student(); // One Object, student2 is reference variable | ||
student2.id = 45; | ||
student2.name = "Sam"; | ||
print("${student2.id} and ${student2.name}"); | ||
student2.study(); | ||
student2.sleep(); | ||
} | ||
|
||
// Define states (properties) and behavior of a Student | ||
class Student { | ||
int id = -1; // Instance or Field Variable, default value is -1 | ||
String name; // Instance or Field Variable, default value is null | ||
|
||
void study() { | ||
print("${this.name} is now studying"); | ||
} | ||
|
||
void sleep() { | ||
print("${this.name} is now sleeping"); | ||
} | ||
} |