Skip to content

Commit

Permalink
Inheritance with Named and Default Constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
smartherd committed Jul 2, 2018
1 parent f089942 commit 8b3f036
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions 24_inheritance_with_constructors.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

// Objectives
// 1. Inheritance with Default Constructor and Parameterised Constructor
// 2. Inheritance with Named Constructor

void main() {

var dog1 = Dog("Labrador", "Black");

print("");

var dog2 = Dog("Pug", "Brown");

print("");

var dog3 = Dog.myNamedConstructor("German Shepherd", "Black-Brown");
}

class Animal {

String color;

Animal(String color) {
this.color = color;
print("Animal class constructor");
}

Animal.myAnimalNamedConstrctor(String color) {
print("Animal class named constructor");
}
}

class Dog extends Animal {

String breed;

Dog(String breed, String color) : super(color) {
this.breed = breed;
print("Dog class constructor");
}

Dog.myNamedConstructor(String breed, String color) : super.myAnimalNamedConstrctor(color) {
this.breed = breed;
print("Dog class Named Constructor");
}
}

0 comments on commit 8b3f036

Please sign in to comment.