-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path#24-Default _Constuctor.dart
More file actions
47 lines (35 loc) · 1.3 KB
/
#24-Default _Constuctor.dart
File metadata and controls
47 lines (35 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
void main(){
//Object oriented Programming in Dart
//Constructor in Dart
//Constructor is special method, it Can create object or it is executed when we the object of a class is created.
/* Types of Constructor
* 1 Default Constructor
* 2 parameterized Constructor
* 3 Named Constructor
* 4 Constant Constructor
*/
//Default Constuctor in Dart
var student1 = Student();//Default Constructor
//it is Called default constructor if we add executable code in constructor it will execute
//every time we create object from class, see below in class -->
student1.name = "souvik";
student1.id = 23;
print("${student1.id} > ${student1.name}");
student1.sleep();
var student2 = Student();
student2.name = "sam";
print(student2.name);
//actually objects inherit the properties and method / behavior of a class
}
//we can't create default Constructor and Parameterized Constructor in the same class
class Student{
int id;
String name;
//it although look like function but Constructor Doesnot have return type.
Student(){ //we add executable code in default constuctor.
print("Hello Constuctor--> this time is constuctor executed");
}
void sleep(){
print("${this.name}'s sleep too much");
}
}