
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sobrecarga
{
class Suma
{
public int Sumar(int a, int b)
{
int x = a + b;
return x;
}
public int Sumar(int a, int b, int c)
{
int x = a + b + c;
return x;
}
public int Sumar(int a, int b, int c, int d)
{
int x = a + b + c + d;
return x;
}
public int Sumar(int a, int b, int c, int d, int e)
{
int x = a + b + c + d + e;
return x;
}
public int Sumar(int a, int b, int c, int d, int e, int f)
{
int x = a + b + c + d + e + f;
return x;
}
}
}
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sobrecarga
{
class Program
{
static void Main(string[] args)
{
Suma f = new Suma();
int z = f.Sumar(1, 2);
int j = f.Sumar(1, 2, 3, 4);
Console.WriteLine("el valor de z es {0} y el valor de j es {1}", z,j);
}
}
}

clase Animal
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sobreescritua
{
class Animal
{
private int numero_patas;
private bool tiene_cola;
private string nombre;
private int años;
public int Numero_patas { get => numero_patas; set => numero_patas = value; }
public bool Tiene_cola { get => tiene_cola; set => tiene_cola = value; }
public string Nombre { get => nombre; set => nombre = value; }
public int Años { get => años; set => años = value; }
public Animal() { }
public Animal(int numero_patas, bool tiene_cola, string nombre, int años)
{
this.numero_patas = numero_patas;
this.tiene_cola = tiene_cola;
this.nombre = nombre;
this.años = años;
}
public virtual string Hacersonido()
{
return "arrhhh";
}
public void Comer() { }
public void Dormir() { }
}
}
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sobreescritua
{
class Perro : Animal
{
private string raza;
private bool es_amigable;
private bool cola_mocha;
public string Raza { get => raza; set => raza = value; }
public bool Es_amigable { get => es_amigable; set => es_amigable = value; }
public bool Cola_mocha { get => cola_mocha; set => cola_mocha = value; }
public Perro() { }
public Perro(string raza, bool es_amigable, bool cola_mocha)
{
this.raza = raza;
this.es_amigable = es_amigable;
this.cola_mocha = cola_mocha;
}
public override string Hacersonido()
{
base.Hacersonido();
return "guau guau";
}
}
}
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sobreescritua
{
class Gato : Animal
{
private bool es_domestico;
private string color_pelaje;
public bool Es_domestico { get => es_domestico; set => es_domestico = value; }
public string Color_pelaje { get => color_pelaje; set => color_pelaje = value; }
public Gato() { }
public Gato(bool es_domestico, string color_pelaje)
{
this.es_domestico = es_domestico;
this.color_pelaje = color_pelaje;
}
public override string Hacersonido()
{
base.Hacersonido();
return "miau miau";
}
}
}
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sobreescritua
{
class Vaca : Animal
{
private bool es_lechera;
private bool tiene_cacho;
public bool Es_lechera { get => es_lechera; set => es_lechera = value; }
public bool Tiene_cacho { get => tiene_cacho; set => tiene_cacho = value; }
public Vaca() { }
public Vaca(bool es_lechera, bool tiene_cacho)
{
this.es_lechera = es_lechera;
this.tiene_cacho = tiene_cacho;
}
public override string Hacersonido()
{
base.Hacersonido();
return "muuuuuu";
}
}
}
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sobreescritua
{
class Pollito : Animal
{
private string color;
public string Color { get => color; set => color = value; }
public Pollito() { }
public Pollito(string color)
{
this.color = color;
}
public override string Hacersonido()
{
base.Hacersonido();
return "pio pio";
}
}
}
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sobreescritua
{
class Program
{
static void Main(string[] args)
{
Animal pio = new Pollito();
Animal lola = new Vaca();
Animal michi = new Gato();
Animal firulais = new Perro();
Console.WriteLine("el perro firulais hace {0}, el gato michi hace {1}, la vaca lola hace {2} y el pollito pio hace {3}", firulais.Hacersonido(), michi.Hacersonido(), lola.Hacersonido(), pio.Hacersonido());
Console.ReadKey();
}
}
}
