I have a simple Java program to generate a random dice facing - code below:
Dice facing class
class Dice
{
private int face;
public Dice()
{
System.out.println(face());
}
public int getFace()
{
return face;
}
public void setFace(int face)
{
this.face = face;
}
private int face()
{
face = (int)(Math.random() * 7);
return face;
}
}
Main class
class John
{
public static void main (String [] args)
{
Dice dice = new Dice();
System.out.println(dice);
}
}
When I do a println, it returns this:
5
Dice@6d06d69c
I have no idea why there is a Dice@6d06d69c. Why will this appear and how can I modify it to prevent it from appearing?
Thank you.