1class MyClass {
2 int param1;
3 MyClass(this.param1);
4}
5final obj = MyClass(100);
6
7class MyClassNamed { // with named parameters
8 int param1;
9 MyClassNamed({required this.param1});
10}
11final objNamedParam = MyClassNamed(param1: 100);
1class Person {
2 String name;
3 int age;
4 Person({this.name = '', this.age = 0});
5}
6
7void main() {
8 Person person1 = Person(name: "Raaj", age: 35);
9 print(person1.age);
10}
1class Customer {
2 String name;
3 int age;
4 String location;
5
6 // constructor
7 Customer(String name, int age, String location) {
8 this.name = name;
9 this.age = age;
10 this.location = location;
11 }
12}
13
1class Chipmunk {
2 String name;
3 int fame;
4
5 Chipmunk.named(this.name, [this.fame]);
6
7 Chipmunk.famous1() : this.named('Chip', 1000);
8 factory Chipmunk.famous2() {
9 var result = new Chipmunk.named('Chip');
10 result.fame = 1000;
11 return result;
12 }
13}
14
1void main() {
2 Human jenny = Human(height1 :15);
3 print(jenny.height);
4
5 Human jerry = Human(height1: 20);
6 print(jerry.height);
7}
8
9class Human {
10 double height = 0;
11
12 Human({height1 = 0}) { // constructor = initializes values of properties in the class.
13 this.height = height1;
14 }
15
16}
17
1Customer(String name, int age, String location) {
2 this.name = name;
3 this.age = age;
4 this.location = location;
5}
6
7Customer(this.name, this.age) {
8 this.name = name;
9 this.age = age;
10}
11