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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:05:45+00:00 2026-05-30T03:05:45+00:00

I am a beginning programmer and came across this in my textbook: public boolean

  • 0

I am a beginning programmer and came across this in my textbook:

public boolean equals(DataElement otherElement)
{
    IntElement temp = (IntElement) otherElement;            
    return (num == temp.num);
}

IntElement is a subclass of DataElement. num is an int storing a value for a linked list.

What is the purpose of (IntElement) after temp =? What would be wrong with IntElement temp = otherElement? And, in general, what does putting a data type in parentheses like that do?

  • 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-30T03:05:46+00:00Added an answer on May 30, 2026 at 3:05 am

    This is called casting, see here:

    • http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html

    Basically, by doing this:

    IntElement temp = (IntElement) otherElement;  
    

    you are telling compiler to ignore the fact you declared otherElement as DataElement and trust you it is going to be an IntElement and not DataElement or some other subclass of DataElement.

    You cannot do just IntElement temp = otherElement; as this way you would make otherElement, which was defined as DataElement become some other element, in this case IntElement. This will be a big blow to type-safety, which is the reason types are defined at the first place.

    This could technically be done using type inference:

    • http://en.wikipedia.org/wiki/Type_inference

    however Java does not support that and you have to be explicit.

    If it’s possible to get other elements, you may want to use instanceof to check the type runtime before casting:

    • Operators/TheinstanceofKeyword.htm”>http://www.java2s.com/Tutorial/Java/0060_Operators/TheinstanceofKeyword.htm

    At some point after you go through this, you might want to take a look at generics, too:

    • http://en.wikipedia.org/wiki/Generics_in_Java
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would you approach this exercise, as a beginning programmer? It is a classroom
As a beginning programmer, I'm trying to settle on a standard naming convention for
I'm a beginning programmer and the I&CS program at our school starts us off
On paper, binary arithmetic is simple, but as a beginning programmer, I'm finding it
I am a beginning javascript programmer. I am trying to create something similar to
Many beginning programmers write code like this: sub copy_file ($$) { my $from =
I am a beginning C programmer (though not a beginning programmer) looking to dive
So, Im a beginning C# programmer. I know basic syntax and simple things like
I'm a beginning python programmer, and I'd like someone to clarify the following behavior.
As a beginning iPhone programmer, what is the best practice for writing apps to

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.