Advertisement
jacknpoe

Polimorfismo em Tempo de Execução em C#

Feb 2nd, 2024
1,242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | Source Code | 0 0
  1. using System;
  2.  
  3. class Animal {
  4.     virtual public string move() {
  5.         return "anda";
  6.     }
  7. }
  8.  
  9. class Cobra : Animal {
  10.     override public string move() {
  11.         return "rasteja";
  12.     }
  13. }
  14.  
  15. class Peixe : Animal {
  16.     override public string move() {
  17.         return "nada";
  18.     }
  19. }
  20.  
  21. class Aula34 {
  22.     static void Main(string[] args)     {
  23.         Cobra cobra = new Cobra();
  24.         Peixe peixe = new Peixe();
  25.  
  26.         info("cobra", cobra);
  27.         info("peixe", peixe);
  28.     }
  29.  
  30.     static void info(string nome, Animal animal) {
  31.         Console.WriteLine("O {0} {1}.", nome, animal.move());
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement