-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path27_Inheritance.dart
More file actions
78 lines (49 loc) · 1.15 KB
/
Copy path27_Inheritance.dart
File metadata and controls
78 lines (49 loc) · 1.15 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Inheritance theory..
/*
1. Inheritance is a mechanisam in which on object acquires properties of its parent class object.
2. Super class of any class is object:
3. toString - return the String represantation of objects.
4. hash code - Getter, Returns the hash code of an objects.
5. Operator == , to compare to objects.
Advantages.
1. code reusability .
2. Method overriding.
3. Cleaner code no reputation.
*/
void main(){
Dog dog = new Dog();
dog.bread = "Labrador";
dog.color = "black";
dog.eat();
dog.bark();
dog.toString();
Cat cat = new Cat();
cat.color = "Brown";
cat.age = 50;
cat.eat();
cat.meow();
cat.toString();
var animal = new Animal();
animal.eat();
animal.color = "Black";
}
class Animal{
String color;
void eat(){
print("eat !");
}
}
// create a child class
class Dog extends Animal{
String bread;
void bark(){
print("Bark is calling");
}
}
// create a child class.
class Cat extends Animal{
int age;
void meow(){
print("meow !");
}
}