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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:44:19+00:00 2026-05-31T00:44:19+00:00

I’m practicing learning how to write classes and creating is relationships between objects. In

  • 0

I’m practicing learning how to write classes and creating “is” relationships between objects. In the code below, the first class “Person” defines a Person, and then in the second class “MarryDemo”, I see whether someone is married, who that spouse is, their address, etc. They even get divorced very shortly thereafter. The code is based on the examples of Jan Skansholm Java from the Beginning.

The problem is that I expected the result of the main method in MarryDemo to be “Kris Humphries”, “43 New Jersey Jets Street”, “null”, but instead of the spouse name I got Person@558ee9d6, with the spouse’s address and the spouse after divorce remaining as I expected them to be.

What does Person@558ee9d6 signify? Is that the location of the object that is referenced by the name “Kris Humphries”? Why does Person@558ee9d6 appear instead of the name?

//defines a person
public class Person {
    //instance variables
    private String name, address;
    private Person spouse;

    //constructor
    public Person(string n) {
        name = n;
    }

    //instance methods
    public String getName() {
        return name;
    } 

    public void marry(Person p) {
      spouse = p; 
      p.spouse = this; 
    }

    public Person isMarriedTo() {
        return spouse;
    }

    ... //more methods for returning address, divorcing, etc.

    }

//
public class MarryDemo {
    public static void main (String[] arg) {
    String name1 = "Kim Kardashian";
    String name2 = "Kris Humphries";

    Person p1 = new Person(name1);
    Person p2 = new Person(name2);

    p1.marry(p2);
    System.out.println(p1.marriedTo());

    p2.setAddress("43 New Jersey Jets Drive");
    System.out.println(p1.marriedTo().getAddress());

    p1.divorce();
    System.out.println(p1.marriedTo());

    }
}
  • 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-31T00:44:20+00:00Added an answer on May 31, 2026 at 12:44 am

    You need to implement a toString() method (as the default is not suitable). Most IDE will generate one for you.

    What does Person@558ee9d6 signify?

    The class name and identity of the object. See Object.toString() for the code.

    Is that the location of the object that is referenced by the name “Kris Humphries”?

    Nothing to do with the name. It is Person.toString() you are calling.

    Why does Person@558ee9d6 appear instead of the name?

    Where do you say you want the name to be printed instead?


    If I replace string with String and use the IDE to generate a toString, the default is

    @Override
    public String toString() {
        return "Person{" +
                "address='" + address + '\'' +
                ", name='" + name + '\'' +
                ", spouse=" + spouse +
                '}';
    }
    

    This is obviously not suitable as this will go around forever. You can change it to

    @Override
    public String toString() {
        return "Person{" +
                "address='" + address + '\'' +
                ", name='" + name + '\'' +
                ", spouse=" + spouse != null ? spouse.getName() : " {none}" +
                '}';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.