Feb 02 2009
Java: Getters and Setters
- Let you get and set instance variables
- Getter: sends back (as a return value) the value of what the getter is getting
- Setter: takes an argument value and uses it to set the value of an instance variable
public class ElectricGuitar { String brand; int numOfPickups; boolean rockStarUsesIt; return brand; } brand = aBrand; } int getNumOfPickups() { return numOfPickups; } void setNumOfPickups (int num) { numOfPickups = num; } boolean getRockStarUsesIt() { return rockStarUsesIt; } void setRockStarUsesIt(boolean yesOrNo) { rockStarUsesIt = yesOrNo; } }