Hiteshw11

Classes In Dart

Nov 24th, 2024
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.82 KB | Source Code | 0 0
  1. // Classes In Dart
  2.  
  3. void main()
  4. {
  5.   var pasta = MenuItems("Spaghetti",7.99);
  6.   var chicken = MenuItems("Tenders",5.99);
  7.   print(chicken.format());
  8.   print(pasta.format());
  9.   var pizza = PizzaDish("Pan Pizza",10.99,["Peppers","Onions"]);
  10.  
  11.  
  12.   print(pizza.format()); // pizza can use this method because it has inherited the ckass
  13.   print(pizza.Details());
  14. }
  15.  
  16. class MenuItems
  17. {
  18.   String title;
  19.   double price;
  20.  
  21.   MenuItems(this.title,this.price);
  22.  
  23.   String format()
  24.   {
  25.     return "$title ---> $price";
  26.   }
  27. }
  28.  
  29. class PizzaDish extends MenuItems
  30. {
  31.   List<String> toppings;
  32.  
  33.   PizzaDish(super.title,super.price,this.toppings);
  34.  
  35.   String Details()
  36.   {
  37.     return "${title}-->${toppings}-->${price}";
  38.   }
  39. }
  40.  
  41.  
  42. /* Output
  43.  
  44. Tenders ---> 5.99
  45. Spaghetti ---> 7.99
  46. Pan Pizza ---> 10.99  */
  47.  
  48.  
Tags: dart
Add Comment
Please, Sign In to add comment