Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8052899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:40:56+00:00 2026-06-05T07:40:56+00:00

Folks I came across many threads for understanding polymorphism (Both compile time and run

  • 0

Folks

I came across many threads for understanding polymorphism (Both compile time and run time). I was surprised to see some links where the programmers are claiming Overloading is Runtime and Overriding is compile time.

What I want to know from here is:

  1. Runtime Polymorphism with a REAL TIME example and small code and what scenario we should use.
  2. Compile time Polymorphism with REAL TIME example and small code and when to use.

Because I read many theoretical definitions, but I am not satisfied in understanding that.

Also, I gave a thought, that where I also felt, overloading should be runtime as because, say I have a method that calculates Area, at runtime only it decides which overloaded method to call based on parameters I pass (Say if I pass only one parameter, it should fire Square, and if parameters are 2, it should fire Rectangle)….So isn’t it I can claim its runtime ? How its complie time ? (Most say theoretically, overloading is compile time but they dont even give a correct REAL time example…very few claim its runtime)….

Also, I feel overriding is compile time because, while you write code and complie, you ensure you used virtual keyword and also overriding that method in derived class which otherwise would give you compile time error. So I feel its compile time, the same way where I saw in a thread…..But most threads claims its runtime 😀

I am confused 🙁 This question is additional to my question 1 and 2. Please help with a real time example.. as I am already aware of theoretical definitions …. 🙁

Thank you….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:40:58+00:00Added an answer on June 5, 2026 at 7:40 am

    In the case of Overloading, you are using static (compile-time) polymorphism because the compiler is aware of exactly which method you are calling. For example:

    public static class test
    {
        static void Main(string[] args)
        {
            Foo();
            Foo("test");
        }
    
        public static void Foo()
        {
            Console.WriteLine("No message supplied");
        }
    
        public static void Foo(string message)
        {
            Console.WriteLine(message);
        }
    }
    

    In this case, the compiler knows exactly which Foo() method we are calling, based on the number/type of parameters.

    Overriding is an example of dynamic (runtime) polymorphism. This is due to the fact that the compiler doesn’t necessarily know what type of object is being passed in at compile-time. Suppose you have the following classes in a library:

    public static class MessagePrinter
    {
        public static void PrintMessage(IMessage message)
        {
            Console.WriteLine(message.GetMessage());
        }
    }
    
    public interface IMessage
    {
        public string GetMessage();
    }
    
    public class XMLMessage : IMessage
    {
        public string GetMessage()
        {
            return "This is an XML Message";
        }
    }
    
    public class SOAPMessage : IMessage
    {
        public string GetMessage()
        {
            return "This is a SOAP Message";
        }
    }
    

    At compile time, you don’t know if the caller of that function is passing in an XMLMessage, a SOAPMessage, or possibly another type of IMessage defined elsewhere. When the PrintMessage() function is called, it determines which version of GetMessage() to use at runtime, based on the type of IMessage that is passed in.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

folks. So, I've came across this compilation error a while ago.. As there's an
So I'm learning Scala and came across some examples like this: val doubleEven =
Folks, I am completely new to jQuery and JqGrid both. Usually I take some
Yesterday I read some code of a colleague and came across this: class a_class
I came across an old problem that you Mathematica/StackOverflow folks will probably like and
Folks, Has anyone came across a scenario where they have used SQL server state
Folks, I'm having some problems making a form render/display in my webpage. Well, it
Folks, I really like the -Wshadow option since it helps to spot some possible
I googled and came up blank - so it's time to test the good
Folks, I've been writing some code in Scala lately to teach myself the language

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.