It's tough to keep all these terms straight in my head. Apparently, a modifier statement is different from a constructor, which in turn is completely different from initialization constructor. Each one of these terms makes my head spin, and I can't tell them apart. I didn't think it was going to be much of a problem at first, but when the quiz rolled around, I realized how little I actually knew. For me, the largest problem was keeping everything straight in my head, and matching up the right terms to what I knew needed to be in each class. I finally figured out that the system works like this.
public class ClassName{
<define instance variables>
public ClassName(){ //default constructor
<assign some default values to your instance variables>
}
public void setInstanceVariable(variable){ //modifier method
instancevariable = variable;
}
public <instancevariable datatype> getInstanceVariable(){ //accessor method
return variable;
}
public toString toString(){ //toString method
return ""+ variable;
}
}
Sorry if the post was dry, but i needed to make sure I could write out the concepts for my own use, and so that I could map out what every class should look like. I think the way I learned to identify each component was to think about what each part did in the structure of the class, and to learn the function of each method. For example, the accessor method is a "get______" because it accesses and grabs that variable's value for the user. That helped me spatially place each method in it's place and associate the name with the method. Thanks for reading!
No comments:
Post a Comment