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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:58:28+00:00 2026-06-04T08:58:28+00:00

I have a class Dog extends Animal . Then I call the hashCode() method

  • 0

I have a class Dog extends Animal.

Then I call the hashCode() method as follows.

Animal animal  = new Dog(200);
System.out.println(animal.hashCode());

Here,
If I’ve overridden the hashCode() in the Dog class it will be returned.
Else if I’ve overridden the hashCode() in the Dog class it will be returned.
Else some integer returned.

I wanna know…

  • Why does it call the hashCode() of the super class when it is not
    overriden in the Dog class? How and what the ‘some integer’ generated

  • When the hashCode is not generated in anywhere. (I have heard that it
    is the memory location of the object but not sure.)

  • 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-04T08:58:29+00:00Added an answer on June 4, 2026 at 8:58 am

    This is referred to as method overriding. The hashCode method is defined in java.lang.Object, basically the top of the object heirarchy, so it is always available to any Object defined in Java. If the method is not overriden in your specific subclass or one of its parents, the default behavior defined in java.lang.Object will be invoked.

    You typically should not worry about what the internal implementation of a hash code is in a parent object, but the default implementation does use the internal address of the Object. Note that this internal address is precisely that – an interpreted address that the JVM uses internally, that should not be depended upon by an application to be anything particularly meaningful.

    You can read more about how overriding works in the Java Language Specification – Section 8.4.8.

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

Sidebar

Related Questions

Lets say I have the following code: abstract class Animal case class Dog(name:String) extends
Let's suppose I have a class Dog that inherits from class Animal, you might
I have the following code: class Animal(hair: Option[Hair]) class Cat(var hair: Option[Hair]) extends Animal(hair)
I have an abstract Base class. Let's call it Animal::Base . module Animal class
Say I have models: class Animal(models.Model): type = models.CharField(max_length=255) class Dog(Animal): def make_sound(self): print
For example can I have class Dog { int legs; Bone chewy; Bone squeeky;
i have class named Group i tried to test configuration: var cfg = new
I have one class called dog and another class called cat. Dog has an
Ok so I have a class called Dog() which takes two parameters, a string
I have this model I'm showing in the admin page: class Dog(models.Model): bark_volume =

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.