c# polymorphism

class Animal{
  public virtual void animalSound() {
    Console.WriteLine("The animal makes a sound");
  }
}

class Pig: Animal {
  public  override void animalSound() {//override superclass method
    Console.WriteLine("The pig says: wee wee");
  }
}

class Dog: Animal {
  public override void animalSound() {//override superclass method
    Console.WriteLine("The dog says: bow wow");
  }
}

static class main {
  static void Main(){
    //You can add all objects inherited from Animal to an Animal type list
    Animal[] animals = new Animal[3]; //Creating the Animal List
    animals[0] = new Animal(); //Add a new animal object to the list
    animals[1] = new Dog(); //Add a new dog object to the list
    animals[2] = new Pig(); //Add a pig object to the list
    foreach (Animal a in animals){
      a.animalSound(); //This statement prints the correct string no matter the class
    }
  }
}

0
1
Erikio 85 points

                                    public class X  
{  
    public virtual void A()  
    {  
    }  
}  
public class Y : X  
{  
    public override void A()  
    {  
    }  
}  

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
c# polymorphism static class c# polymorphism interface polymorphism c# easy definition what is polymorphism, give an example in c# new polymorphism c# c# examples of polymorphism oop polymorphism in c# how to implement polymorphism in c# polymorphism c# how many ways we can implement polymorphism in c# polymorphism c# which method does it call c# what is polymorphism polymorphism definition in c sharp why we use polymorphism in c# what is use of polymorphism in c# polymorphism java and c# polymorphic this c# what is the definition of polymorphism in c# what is polymorphism and why we use it in c# polymorphism Example codes c# polymorphism Exemmple codes c# f# polymorphism polymorphism oop c# example polymorphism explained c# what is a polymorphism in oop C#? polymorphism in oops C# what is polymorphism in c# explain with example example of polymorphism in csharp Polymorphism type c# What is Polymorphism c# static why we use polymorphism in c#.net polymorphism class in c# with example polymorphism meaning in c# polymorphism in c# with real time example polymorphism in c# with example code project how to use polymorphism in c# polymorphism syntax in c# polymorphism c sharp runtime polymorphism c# write to program in c# to demonstrate the use of Polymorphism a polymorphism C3 polymorphism types in c# c# class polymorphism user c# cases where you would want to use polymorphism c# do you new the new keyword for polymorphism example of polymorphism in c# polymorphisme c# definition polymorphism .net polymorphism real time example C# c# polymorphism nedir c# polymorphism banking polymorphism c# explained polymorphism in csharp what is polymorphism in c# with real time example method runtime polymorphism in c# class a1 c# polymorphism polymorphism c# project polymorphism in oops example c# principle of polymorphism c# runtime polymorphism in c# example runtime polymorphism in c# polymorphism in c# geeksforgeeks what is type of polymorphism C# compile polymorphism c# c# polymorphism name c# polymorphism definition repodb polymorphism c# polymorphism in c#? different types of Polymorphism in C#? Polymorphism explanation c# different types of polymorphism in c# POLYmorphism c# AND what is c# polymorphism example polymorphism c# types of polymorphism in c# Polymorphism C# nedir polymorphism c# e polymorphism exmple in c# what does Polymorphism mean in c# what is polymorphism in c# with example what does polymorphism mean c# polymorphism practical example in c# polymorphism in oop C# static polymorphism c# rectuangular field with 2 types of resoucres in c# Create class hierarchies and make use of polymorphism in C# C# polymorphism know real type of an object example of polymorphism c# polymorphism in C sharp polymorphic c# definition compile polymorphism in c# polymorphism to create an object c# c# oop polymorphism practice problems polymorphism c# example what is C# Polymorphism C# Polymorphism and types polymorphism program in c# polymorphism in object oriented programming c# polymorphisme c sharp usage of polymorphism in c# polymorphism definition in c# Polymorphism with c# in msdn what is Polymorphism .in C# what is polymorphism c# pdf what is polymorphism c# What is polymorphism with respect to OOP c# polymorphism animal example c# polymorphism example in c# c sharp polymorphism polymorphism in .net framework how to use polymorphism to create an object and call method in c# learnig c# polymorphism polymorphism in c# example Create a C# console application using Generic Interface Implementation and demonstrate its usage for dynamic polymorphism POLYMORPHISM em c# o que e polymorphism c# oop sign up and log in forms in c# using polymorphism polymorphism c# definition c# example of polymorphism can polymorphism be achieved in c# example for polymorphism in c# c# polymorphism class = baseclass example c# polymorphism example opolymorphism c# what is polymorpism c# polymorphic method c# c# basic concept polymorphism oop Polymorphism example c# what is polymorphism in c# polymorphism in c# with example animal polymorphism c# polymorphism means in C# c# polimorfism polymorphism c# polymorphism example c# polymorphism in c# polymorphism java c# polymorphism override example C# polymorphic compiler c# polymorphism
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source