Advertisement
Guest User

Untitled

a guest
Mar 19th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.50 KB | None | 0 0
  1. import std.stdio;
  2.  
  3. interface Animal {
  4.     void sound();
  5. }
  6.  
  7. class Dog : Animal {
  8.     override public void sound() {
  9.         for (int i = 0; i <=3; ++i) write("hau");
  10.         write("\n");
  11.     }
  12. }
  13.  
  14. class Cat : Animal {
  15.     override public void sound() {
  16.         for (int i = 0; i <= 5; ++i) write("miau");
  17.         write("\n");
  18.     }
  19. }
  20.  
  21. void main() {
  22.     Animal[] animals;
  23.  
  24.     animals ~= new Cat;
  25.     animals ~= new Dog;
  26.    
  27.     foreach (animal; animals) {
  28.         animal.sound();
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement