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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:38:33+00:00 2026-05-24T12:38:33+00:00

In Java we need casting when converting double(big in memory size) to Integer (smaller

  • 0

In Java
we need casting when converting double(big in memory size) to Integer (smaller in memory size)

int x = (int) 4.3;

But in case of objects if parent class is “Mammal”(small in memory size) and its subclass is “Human” (big in memory size since got more properties then mammal)

then

Mammal m = new Human(); //works without casting

but small to big conversion

Human h = (Human) m ; // needs casting 

Thanks in Advance.

  • 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-24T12:38:33+00:00Added an answer on May 24, 2026 at 12:38 pm

    Casting is not about the size of the object: it’s about the range of the variable.

    By ‘range’, i mean the variety of different values that the variable can contain. If you assign from one variable to another whose range is a superset of the first, you don’t need to cast, because you know that the assignment will be okay. But when you assign from one variable to another whose range is a subset, you do need to cast, because the assignment might not be possible.

    Imagine you have two containers: a plastic tub and a wire shopping basket, of the same size. Clearly, anything you can keep in the wire basket, you can keep in the tub. But not everything you can keep in the tub can be kept in the basket. A pile of apples, you can. But a pile of raisins, you can’t – they would fall through the holes in the basket. So, the range of things that the tub can hold is greater than the range of things the basket can hold, even though both are the same size.

    In that analogy, casting is like checking whether the thing you’re moving will fit in the new container. You don’t need to check when moving things from the basket to the tub, but you do need to check when moving from the tub to the basket, otherwise you will end up with fruit all over the floor.

    In your specific cases, we know that every human is a mammal, but that not every mammal is a human, so the range of a variable of type Mammal is greater than that of a variable of type Human. We also know that the range of a double (approximately 2^1024 – -(2^1024)) is greater than that of an int (2^31-1 – -2^31). So, assigning from the former to the latter in either case requires a cast, but from the latter to the former does not.

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

Sidebar

Related Questions

In java I need to make a Calendar object from a String in the
Question:- Does java client need to worry about multiple servers ? Meaning:- I have
Possible Duplicate: How to add days to a date in Java I need to
I need a Java code to find the length of a formatted decimal. Eg
I need a Java function that returns the results of a SQL SELECT query
I need a Java library to convert PDFs to TIFF images. The PDFs are
I need a Java class to submit tickets to BMC Remedy's Helpdesk product. Wondering
I need a java script function that converts the document object of the current
I need the java code snippet for the below logic: Following is a string
I need a java program to download a series of file from a web

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.