0

Here is my code.. I am getting memory address when I print this out.

public class Animals {
    String name;
    int age;
    public Animals(String name, int age) {
        this.name = "Jack";
        this.age = 33;
    }

    public static void main(String[] args) {
        Animals person1 = new Animals("Jimmy", 5555);

        System.out.println(person1);


    }
}
RamPrakash
  • 1,663
  • 3
  • 20
  • 25
Steve
  • 7
  • 3
  • 1
    Does this answer your question? [I am getting the memory address from an arraylist, need info](https://stackoverflow.com/questions/18929145/i-am-getting-the-memory-address-from-an-arraylist-need-info) – SDJ Jan 20 '20 at 18:24
  • 3
    What you get is not a memory address, but the object's hashcode as hex. This is the default behaviour of [`Object::toString`](https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/lang/Object.html#toString()). If you want to change it, override `public String toString()` in class `Animal`. – Turing85 Jan 20 '20 at 18:24

0 Answers0