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

  • Home
  • SEARCH
  • 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 8782599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:36:17+00:00 2026-06-13T20:36:17+00:00

Lets imagine I have a class called Person which is a generalization of another

  • 0

Lets imagine I have a class called Person which is a generalization of another class Man. If I am to make a couple of instances of this class

Man man = new Man();
Person person = new Man();

Now, the compile-time class of the instance being referenced from the variable man is Man and the compile-time class of person is Person while the run-time class of both instances is Man. So far, im completely on board with the terminology because the instances which are created at run-time both are of class Man. But, if I where to cast the man instance as follows

Person personMan = (Person) man;

how come the run-time type of personMan is still Man? Is the run-time class of a instance only set when a new instance is created? Also, is there a way of actually getting the compile time class of a variable at runtime, so I could query what type of class personMan is (getClass would return Man).

Edit: “compile-time class of a class” was a mistake (and doesn’t make much sense). What I meant was variable (hence they question about what type of class personMan is :))

  • 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-13T20:36:19+00:00Added an answer on June 13, 2026 at 8:36 pm

    It’s important to distinguish between three different concepts here:

    • Variables (man, person)
    • References (the values of the variables)
    • Objects (the blobs of memory that the references, um, refer to)

    The type of an object never changes after it’s created. Casting a reference to a different type only affects the compile-time type of that expression. The result of a reference-type cast expression is always the same the original reference – it still refers to the same object, which still has the same type. (That’s leaving boxing aside – and of course the cast can fail at execution time, leading to an exception.)

    Also, is there a way of actually getting the compile time class of a class at runtime

    If you mean the compile-time type of a variable – not if it’s a local variable, without really deep inspection of the byte code. If it’s a field you can use reflection to get at it. Why do you want to know?

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

Sidebar

Related Questions

Let's imagine I have this class : public class FileData { public Weigth {
Hi Imagine I have a class of StandardCar which holds a reference to an
Ok, let's imagine I have an object like this: public class User { public
Let's imagine I have a bash script, where I call this: bash -c some_command
Let's imagine that I have to make a table with the following structure with
Imagine a simple case like this: class Book has_many :chapters end Let's say in
Let's imagine I have a Java class of the type: public class MyClass {
Let's imagine that we have Registry pattern... <?php class Registry { private static $objects
Let's say I have this in my web.xml: <servlet> <description></description> <display-name>MainServ</display-name> <servlet-name>MainServ</servlet-name> <servlet-class>MainServ</servlet-class> </servlet>
I have 1 Interface called A that needs to be implemented by a class

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.