Created
January 17, 2012 02:53
-
-
Save javierguerrero/1624259 to your computer and use it in GitHub Desktop.
herencia en 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 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; | |
} | |
void Cumpleaños() | |
{ | |
Edad++; | |
} | |
} | |
class Trabajador : Persona | |
{ | |
public int Sueldo; | |
public Trabajador(string nombre, int edad, string dni, int sueldo) | |
: base(nombre, edad, dni) | |
{ | |
Sueldo = sueldo; | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Trabajador p = new Trabajador("Javier", 29, "94153043", 5400); | |
Console.WriteLine("Nombre: {0} ", p.Nombre); | |
Console.WriteLine("Edad: {0} ", p.Edad); | |
Console.WriteLine("NIF: {0} ", p.DNI); | |
Console.WriteLine("Sueldo: {0} ", p.Sueldo); | |
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