forked from smartherd/DartTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inheritance with Named and Default Constructors
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |