Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+9 votes

I don't know if I should call the constructor for the Label objects at the top of the code or in the start() method or if either would be fine (this is for the Rollerama lab). It seems to work both ways.

asked in CSC305 Fall 2023 by (1 point)

1 Answer

+5 votes

I don't think it matters in this scenario, but I defined my Label object instance variables inside the start method. I had (Label totalLabel;) outside the start method, then inside the start method I defined totalLabel and called the Label constructer. It shouldn't matter, but defining the instance variables/data fields inside a method allows for more customization. I think doing it this way is cleaner and more specific for other coders to understand as well.

answered by (1 point)
+1

Thank you!

+1

I agree with Braeden, but note that for good coding style (encapsulation), make sure you declare your field (member variable) as private:

private Label totalLabel;

...