Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. / Objectives
  2. // 1. Inheritance with Default Constructor and Parameterised Constructor
  3. // 2. Inheritance with Named Constructor
  4.  
  5. void main() {
  6.  
  7. var dog1 = Dog("Labrador", "Black");
  8.  
  9. print("");
  10.  
  11. var dog2 = Dog("Pug", "Brown");
  12.  
  13. print("");
  14.  
  15. var dog3 = Dog.myNamedConstructor("German Shepherd", "Black-Brown");
  16. }
  17.  
  18. class Animal {
  19.  
  20. String color;
  21.  
  22. Animal(String color) {
  23. this.color = color;
  24. print("Animal class constructor");
  25. }
  26.  
  27. Animal.myAnimalNamedConstrctor(String color) {
  28. print("Animal class named constructor");
  29. }
  30. }
  31.  
  32. class Dog extends Animal {
  33.  
  34. String breed;
  35.  
  36. Dog(String breed, String color) : super(color) {
  37. this.breed = breed;
  38. print("Dog class constructor");
  39. }
  40.  
  41. Dog.myNamedConstructor(String breed, String color) : super.myAnimalNamedConstrctor(color) {
  42. this.breed = breed;
  43. print("Dog class Named Constructor");
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement