Skip to content

Commit

Permalink
Class, Objects, Instance Variable, Functions and Reference Variables
Browse files Browse the repository at this point in the history
  • Loading branch information
smartherd committed Jun 30, 2018
1 parent 78576d9 commit deffdd5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions 19_class_and_objects.dart
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");
}
}

0 comments on commit deffdd5

Please sign in to comment.