Funny @value output

I was playing around to see what happens, and I am getting this output:
Test.Pig@addbf1

What does that mean?

Start.java


package Test;
public class Start {

	public static void main(String[] args)
	{
		Pig p = new Pig();
		System.out.println(p);

	}

}

Animal.java


package Test;
public class Animal {

	String animal;

	void Animal()
	{
		this.animal = "Pig";
	}

}

Pig.java

package Test;


public class Pig extends Animal {


	public String Pig()
	{
		return super.animal;
	}

}

What you’re seeing the memory location of that object.

If you look into the toString() method of the class Object, you’ll see what is going on.

You can change the value that is output if you implemented the toString() in your pig class.

Also, lets change up some of your coding…


public class Animal {
    private String name;

    public Animal(String name) {
        this.name = name;
    }

    public String toString() {
        return this.name;
    }
}


public class Pig extends Animal {

    public Pig() {
        super("Pig");
    }
}

Now you should be able to run your main class and get the results you were looking for.