-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.dart
39 lines (25 loc) · 819 Bytes
/
class.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
37
38
//when we are creating object from a class we use dot notation.when we use map...we use sqare brackets.
void main() {
var noodles = MenuItem("Veg noodles", 9.99);
var pizza = Pizza(["Mushrooms","peppers"],"veg volcano",12.66);
print(noodles.title);
print(noodles.price);
print(pizza.title);
print(pizza.price);
print(noodles.format());
print(pizza.format());
}
class MenuItem {
String title ;
double price ;
MenuItem(this.title,this.price); //"this" will assign value which we will pass inside the constructor to title and price.
String format(){
return "$title --> $price";
}
}
class Pizza extends MenuItem{
List<String> toppings;
// Pizza(this.toppings, String title, double price): super(title,price);
// OR
Pizza(this.toppings,super.title,super.price);
}