Passing objects to classes
Hi
I'm having a problem trying to create a class which contains a group of another class I have made. Basically I have a class called square, which looks like this
Code:
class Square
{
int number;
public Square()
{
}
public void setNumber(int num)
{
if((num > 0) && (num <= 9))
{
set.clear();
set.add(num);
number = num;
}
else
{
System.out.println("You have entered an illegal number");
}
}
public int getNumber()
{
return number;
}
}
And I want to have another class which contains two squares. So something like this.
Code:
class pair
{
public pair(Square s, Square s2)
{
}
}
However, I know this won't really do what I want it to do, as I need the Squares s and s2, to be updated when I update the original square in my main program. So if I did something like this in my main program:
Code:
Square b = new Square();
Square c = new Square();
pair p = new pair(b,c);
c.setNumber(7);
c in pair would update to 7 as well. Is there anyway of doing this? Thanks.