Skip to content

Instantly share code, notes, and snippets.

@javierguerrero
Created January 17, 2012 02:18
Show Gist options
  • Save javierguerrero/1624140 to your computer and use it in GitHub Desktop.
Save javierguerrero/1624140 to your computer and use it in GitHub Desktop.
Clases abstractas C#
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