#simple question
11 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @winged mauve! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Depends on what class Area proposes. Some classes are said immutable: they don't allow to change the values that were set after construction.
if it's not immutable how could you change it
Like I said, it depends on what class Area proposes. In other words, by what mechanism is it not immutable
You could do it in a few ways, easiest is just make the variables you are setting public. Such as:
public class Area {
public int a, b, c, d;
public Area(int a, int b, int c, int d) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
}
}```
you can then modify them by doing:
Area wcArea = new Area(50, 50, 100, 100);
wcArea.a = 100;
// changing other area boundaries as necessary
You can also use getter or setter functions if you need something more complex or the variables need to be private
Fundamentally, setters are an established expectation in Java, even it it smells like cargo cult
That way you will just set the value in the moment that you create the object, so you should create set methods to be able change the attribute values.