-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path29_Inheritance_With_Constructer.dart
More file actions
62 lines (38 loc) · 1.44 KB
/
Copy path29_Inheritance_With_Constructer.dart
File metadata and controls
62 lines (38 loc) · 1.44 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
1. Inheritance with default Constructor and parameterized Constructor..
2. Inheritance with Named Constructor.
3. By default, a Constructor in a sub class calls the super class's no - argument constructor
4. parent class Constructor is always called before child class constructor.
5. If default constructor is missing in parent class, then you must manually call one of the in super class.
*/
void main(){
var dog1 = new Dog("OOps Dog","Black"); // reference value in object declare.
print(" ");
var dog2 = new Dog("Humble Dog", "Brown");
print(" ");
var dog3 = Dog.namedConstructor("German", "Brown");
}
// create a calass
class Animal{
String color;
// Also Declare Default constructor create.
Animal(String color){
this.color = color;
print("Animal is Default Constructor.");
}
Animal.myNamedConstructor(String color){
print("Animal is named constructor");
}
}
//Dog class properties are including in Animal class.
class Dog extends Animal{ //dog is child/sub class Animal is parent/super class.
String breed;
Dog(String breed, String color) : super("Black"){
this.breed = breed;
print("Dog is Default Constructor ..");
}
// this is create named constructor.
Dog.namedConstructor(String breed, String color):super.myNamedConstructor(color){
print("Dog is named constructor with White..");
}
}