Created
January 17, 2012 02:18
-
-
Save javierguerrero/1624140 to your computer and use it in GitHub Desktop.
Clases abstractas C#
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace ConsoleApplication5 | |
{ | |
public abstract class Mascota | |
{ | |
abstract public void hablar(); | |
} | |
public class Gato : Mascota | |
{ | |
public override void hablar() | |
{ | |
Console.WriteLine("Meow"); | |
} | |
} | |
public class Perro : Mascota | |
{ | |
public override void hablar() | |
{ | |
Console.WriteLine("Woof"); | |
} | |
} | |
public class Pato : Mascota | |
{ | |
public override void hablar() | |
{ | |
Console.WriteLine("Quack"); | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Mascota[] misMascotas = new Mascota[4]; | |
misMascotas[0] = new Pato(); | |
misMascotas[1] = new Perro(); | |
misMascotas[2] = new Gato(); | |
misMascotas[3] = new Pato(); | |
for (int i = 0; i < misMascotas.Length; i++) | |
{ | |
misMascotas[i].hablar(); | |
} | |
Console.WriteLine("presione <enter> para terminar"); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment