Monday, 9 September 2013

Set in constructor and can't be changed

Set in constructor and can't be changed

Hey guys I'm working on a program "Franchise". A Franchise has an owner
(the owner of the franchise's name), state (the 2-character string for the
state where the franchise is located), and sales (the total sales at the
franchise for a day) which are all set in a constructor and cannot be
changed.
package prob2;
public class Franchise {
final String name;
final String state;
final double sales;
protected Franchise(String name, String state, double sales ) {
this.name = name;
this.state = state;
this.sales = sales;
}
My question is: Being name, state, and sales have to be set in the
constructor and can't be changed am I doing this right using 'protected'
or is it better to set the variable to 'final'?
Thanks for any and all help.

No comments:

Post a Comment