-
Notifications
You must be signed in to change notification settings - Fork 0
/
#26-Named_Constructor.dart
36 lines (29 loc) · 1.12 KB
/
#26-Named_Constructor.dart
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
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 <!--it is basically important for GUI --!>
*/
//Named constructor in Dart
var student1 = Student.myNamedConstructor(23,"Souvik");
print("${student1.id} and ${student1.name}");
}
//we can't create default Constructor and Parameterized Constructor in the same class.
//But we can create Named Constructor and Paramerterized Constructor in the same class as Many as we want
class Student{
int id;
String name;
//it although look like function but Constructor Doesnot have return type.
/*
Student.myNamedConstructor(){
print("Hello Named Constructor ");//Normal Named Constuctor
}*/
Student.myNamedConstructor(this.id, this.name);//Named Constuctor with Parameter
void sleep(){
print("${this.name}'s sleep too much");
}
}