Skip to content

Commit

Permalink
Dart Inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
smartherd committed Jul 2, 2018
1 parent da65696 commit 6a6ad9e
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions 22_inheritance.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

// Objectives
// 1. Exploring Inheritance

void main() {

var dog = Dog();
dog.breed = "Labrador";
dog.color = "Black";
dog.bark();
dog.eat();

var cat = Cat();
cat.color = "White";
cat.age = 6;
cat.eat();
cat.meow();

var animal = Animal();
animal.color = "brown";
animal.eat();
}

class Animal {

String color;

void eat() {
print("Eat !");
}
}

class Dog extends Animal { // Dog is Child class or sub class, Animal is super or parent class

String breed;

void bark() {
print("Bark !");
}
}

class Cat extends Animal { // Cat is Child class or sub class, Animal is super or parent class

int age;

void meow() {
print("Meow !");
}
}

0 comments on commit 6a6ad9e

Please sign in to comment.