Advertisement
Hiteshw11

Method Overriding in classes in Dart

Nov 25th, 2024
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.41 KB | Source Code | 0 0
  1. void main() {
  2.   var cat=Animal('Snowbell');
  3.   var doggy=Dog("buddy","barks");
  4.   print(doggy.makesound());
  5.   print(cat.makesound());
  6. }
  7.  
  8.  
  9. class Animal
  10. {
  11. String name;
  12.  
  13. Animal(this.name);
  14.  
  15. String makesound()
  16. {
  17. return '$name makes sound';
  18. }
  19.  
  20. }
  21.  
  22. class Dog extends Animal
  23. {
  24. String sound;
  25.  
  26. Dog(String name,this.sound):super(name);
  27.  
  28. @override
  29. String makesound()
  30. {
  31.  
  32.  
  33.  
  34. return '$name $sound';
  35. }
  36. }
  37.  
Tags: dart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement