Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Polymorfi {
- class Program {
- static void Main(string[] args) {
- List<Animal> animals = new List<Animal>();
- animals.Add(new Dog());
- animals.Add(new Dog());
- animals.Add(new Cat());
- for(int i = 0; i < animals.Count; i++) {
- Console.WriteLine(animals[i].Sound());
- }
- Console.ReadKey(true);
- }
- }
- public abstract class Animal {
- public abstract string Sound();
- }
- public class Cat : Animal {
- public Cat() { }
- public override string Sound() {
- return ("Mjau");
- }
- }
- public class Dog : Animal {
- public Dog() { }
- public override string Sound() {
- return ("Vov");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement