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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:38:22+00:00 2026-06-13T07:38:22+00:00

If I have two classes, A and B where B derives from A: class

  • 0

If I have two classes, A and B where B derives from A:

class A {}
class B : A { }

I can upcast quite happily an instance of B to A.

B b = new B();
A a = b;

Now, I can understand how the runtime can determine that the underlying type is B, as page 132 of the ECMA-335 (Common Language Infrastructure (CLI) Partitions I to VI) states

Objects of instantiated types shall carry sufficient information to
recover at runtime their exact type (including the types and number of
their generic arguments). [Rationale: This is required to correctly
implement casting and instance-of testing, as well as in reflection
capabilities

So, how does the runtime know that although the underlying type is B it is in fact stored in an A. I know for a fact that I won’t see the methods available on B, but if the underlying type is B, how does it store the type of the storage location A?

Does that make sense?

  • 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-13T07:38:24+00:00Added an answer on June 13, 2026 at 7:38 am

    The object is a B, and the CLI knows it is a B. The thing that knows about A is mainly the compiler, which then declares the field or local as being of type A (or, in some cases like method chaining, the type is known via the return type of the method, which is stamped hard into the caller’s IL). So basically: the calling code itself is what says “I think this is an A”. The assignments etc are usually all verifiable in advance, so there is no risk of getting it wrong. If you try to hack the IL to deliberately get it wrong the runtime will tell you off and refuse to run the method. And for these reasons, the assignment of a known-to-be-B value to an A local/field does not require any type checking – it is just a direct assignment.

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

Sidebar

Related Questions

I have a class Derived that inherits directly from two base classes, Base1 and
I have two classes (MVC view model) which inherits from one abstract base class.
I have two classes, one that inherits from the other. The base class is
I have two classes, derived from a common class. The common class has a
I have two classes, Person and Company, derived from another class Contact. They are
I have two classes ClassA and CLassB. ClassA is an abstract class. ClassB derives
I have two different classes deriving from one base class. They each have a
I have two classes derived from BankAccount class – FixedBankAccount and SavingsBankAccount. This is
I have two classes - one base class and one derived from it :
I have two Parser classes that inherit from a base class, BaseParser. I want

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.