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 6999045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:29:24+00:00 2026-05-27T20:29:24+00:00

I’m studying inheritance and polymorphism now and I’ve came across the concept that the

  • 0

I’m studying inheritance and polymorphism now and I’ve came across the concept that the compiler will evaluate (using reflection?) what type of object is stored in a base-type reference in order to decide what method to run upon calling a method with an override.

So for example:

class Shape
{
    public virtual void Draw()
    {
        Console.WriteLine("Drawing shape...");
    }
}

class Circle : Shape
{
    public override void Draw()
    {
        Console.WriteLine("Drawing circle...");
    }
}

static void Main()
{
    Shape theShape = new Circle();
    theShape.Draw();
}

The following will be output:

Drawing circle...

It’s always been my understanding that on declaring any type of object it’s a way of sort of designating memory for that specific type of object. So Int32 i = 2l; would mean that I have now put memory aside as a sort of ‘placeholder’ for an integer. But in the code above I’ve put memory aside for a Shape but it can infact reference/store an object of type Circle!?

  • 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-05-27T20:29:25+00:00Added an answer on May 27, 2026 at 8:29 pm

    All class variables in C# (and in Java) are actually only references – in contrast to the so-called primitive types (e.g. int, float) and structs; the actual space for the Circle object is reserved when you write new Circle(), Shape theShape only reserves space for the reference!

    Any reference variable can hold a reference to all derived types; the actual resolution of which method to call (if it is declared virtual) happens by using virtual method tables at runtime (not via Reflection).

    To explain what polymorphism can be used for (quoting wikipedia):

    [It] allows values of different data types to be handled using a uniform interface.

    The common interface for the Shape objects, in your case would be the Draw() method. It would make perfect sense to have a list of Shapes, and calling the Draw() method on each of them to display them. Meaning, that in order to view all Shapes, your program wouldn’t need to take care what kinds of Shapes are stored in this list – all the proper Draw() methods would be called automatically.

    Every class variable automatically being a reference is one of the big differences of C# (and Java) to languages like C++, where you can decide where you want your variable to live; for a Circle to be of value type (in C++), you’d write:

    Circle circle;
    

    If you instead want to point to it, you’d write

    Circle * circle = new Circle();
    

    Java and C# don’t have an explicit sign making a variable a “pointer” or “reference” – simply every variable which should hold an object is a pointer/reference!

    Also note that (e.g. in C++) you can only use polymorphism if you use pointers or references; that’s because value types can just be accessed as what they were declared, and not more; with references and pointers, when your actual variable is only referencing to / pointing at something, it can point to a number of things (whatever the compiler allows it to point to).

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into

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.