Created
January 17, 2012 02:51
-
-
Save javierguerrero/1624252 to your computer and use it in GitHub Desktop.
métodos virtuales
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 ConsoleApplication4 | |
{ | |
class Persona | |
{ | |
public string Nombre; | |
public int Edad; | |
public string DNI; | |
public Persona(string nombre, int edad, string dni) | |
{ | |
Nombre = nombre; | |
Edad = edad; | |
DNI = dni; | |
} | |
public virtual void Cumpleaños() | |
{ | |
Edad++; | |
Console.WriteLine("Incrementada edad de persona"); | |
} | |
} | |
class Trabajador : Persona | |
{ | |
public int Sueldo; | |
public Trabajador(string nombre, int edad, string dni, int sueldo) | |
: base(nombre, edad, dni) | |
{ | |
Sueldo = sueldo; | |
} | |
public override void Cumpleaños() | |
{ | |
Edad++; | |
Console.WriteLine("Incrementa edad de trabajador"); | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Persona p = new Persona("Carlos", 22, "94156789"); | |
Trabajador t = new Trabajador("Josan", 22, "94153043", 5200); | |
t.Cumpleaños(); | |
p.Cumpleaños(); | |
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