Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.stdio;
- class Animal
- {
- string nome;
- this(string nome)
- {
- this.nome = nome;
- }
- void andar()
- {
- writeln(this.nome ~ " andou!");
- }
- }
- class Cao : Animal
- {
- this(string nome)
- {
- super(nome);
- }
- void latir()
- {
- writeln(this.nome ~ " latiu");
- }
- }
- class Gato : Animal
- {
- this(string nome)
- {
- super(nome);
- }
- void miar()
- {
- writeln(this.nome ~ " miou");
- }
- }
- /* Sistema */
- void processar(ref Animal animal)
- {
- animal.andar();
- }
- void main()
- {
- auto cao = new Cao("Lilico");
- auto gato = new Gato("Fred");
- Animal[] animais = [cao, gato];
- foreach(animal; animais)
- {
- processar(animal);
- }
- cao.latir();
- gato.miar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement