CCCPaste

Zwierzęta z if

// Klasa zwierząt
// Kury
// Krowy

public abstract class Animal
{
public virtual void Eat()
{
Console.WriteLine("Zwierze je");
}

public abstract void TakeSound();
}

public class Cow : Animal
{
public override void TakeSound()
{
System.Console.WriteLine("Krowa robi muuu");
}

public override void Eat()
{
System.Console.WriteLine("Krowa je trawę");
}
}

public class Hen : Animal, IFly
{
public void Fly()
{
System.Console.WriteLine("kura lata");
}

public override void TakeSound()
{
System.Console.WriteLine("kura robi ko ko");
}
}

public class Program
{
public static void Main()
{
Animal[] animals = new Animal[4];

Cow mucka = new Cow();
Cow klarabella = new Cow();

Hen kwoka = new Hen();
Hen hen1 = new Hen();

animals[0] = mucka;
animals[1] = klarabella;
animals[2] = kwoka;
animals[3] = hen1;

foreach (var animal in animals)
{
animal.TakeSound();
animal.Eat();
if (animal is IFly fly)
{
fly.Fly();
}
}
}
}

public interface IFly
{
void Fly();
}


//Osoba
//Uczeń // Nauczyciel //Trener
// wykonaj ćwiczenie() wykonaj ćwiczenie()



// PanStefan : Nauczyciel, Trener

// panStefan.wykonaj ćwiczenie()

//Interface