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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:11:49+00:00 2026-05-17T22:11:49+00:00

This is a beginner’s question, but I am interested in learning what’s going on

  • 0

This is a beginner’s question, but I am interested in learning what’s going on here. My question is, what goes on behind the scenes when you down-cast an object? Does it maintain some sort of metadata about what it originally was? Here’s what I mean:

Suppose I have a method called “ClockIn” that accepts a parameter of type “Employee”:

public static void ClockIn(Employee employee)
{
   var manager = employee as Manager;
   if (manager != null)
   {
      manager.OpenSafe();
   }
}

So, assume that Manager is a subclass of the Employee type and that it has the “OpenSafe” method:

public class Manager : Employee 
{
   public void OpenSafe()
   { 
      ... 
   }
}

The “ClockIn” method, if it finds that a Manager has been passed in, calls the OpenSafe method. Such as:

var bob = new Manager();
ClockIn(bob);

Here, I’ve passed in an instance of type Manager into a method that accepts the base class Employee. I need to cast the instance inside the ClockIn method to Manager before I can call OpenSafe.

The question is, is there some metadata that remembers that “bob” is a Manager, even though I’ve passed him in as an Employee? How does the code know that he can indeed be cast to a Manager? Is there something going on in the heap?

  • 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-17T22:11:50+00:00Added an answer on May 17, 2026 at 10:11 pm

    The first thing to remember is that casting does not change the original object at all. It only changes your view of the object through that particular reference. More than one reference can be pointing to the same object, so changing the object isn’t a reasonable thing to do on a cast.

    What you might do in your instance is to make ClockIn() a method of the Employee class. Then, when you call

    bob.ClockIn();
    

    then bob will know what type he really is, and call the appropriate ClockIn() method for his type. This is called dynamic method dispatch and is not available for static functions as in your example.

    For example:

    public class Employee {
        public void ClockIn() {
            ....
        }
    }
    
    public class Manager: Employee {
        public void ClockIn() {
            // first, do what all Employees do when clocking in
            Employee.ClockIn();
            // Next, do Manager specific actions
            OpenSafe();
        }
        public void OpenSafe() {
            ....
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies as I'm a bit of a beginner with this. I'm trying to send
Hi i am a beginner, and I have this homework for my beginning C
I am a beginner in developing for the Android, so excuse me if this
Beginner question. My goal is to add documents to my CouchDB database on a
A beginner's question: I am trying to remove a subview after having added it
A PyQT beginner question. I'm wondering how to do something like the following -
I am complete beginner to CakePHP but I am a bit knowledgeable in ROR.
an anyone look at this simple code (?) and tell me what's wrong please?
i am a beginner in iphone programming ,i found the following code on a
I am new to XML and Linq to XML and I just can't find

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.