开发者

How do you call a mutator from within a constructor in the same class?

开发者 https://www.devze.com 2023-02-02 05:31 出处:网络
For a homework assignment the instructions state (within Undergrad class): You do NOT need to include a default constructor, but you must write a full parameterized constructor (it takes 4 arguments)

For a homework assignment the instructions state (within Undergrad class):

You do NOT need to include a default constructor, but you must write a full parameterized constructor (it takes 4 arguments) -- this constructor calls the parent class parameterized constructor and the mutator for year level.

Because Undergrad extends Student, then Student is my parent class, right? I just can't quite figure out how I'm to use my year level mutator (which is just the simplest of methods) to assign my "year" attribute.

    public void setYear(int inYear)
{
    year = inYear;
}

public Student(String inName, String inID, int inCredits)
{
    name = inName;
    id = inID;
    credits = inCredits;
}

    public Undergrad(String inName, String inID, int inCredits,int inYear)
{
    super(inName, inID, inCredits);
    year = inYear;
}

I keep missing assignments because I spend too much time on these small specific points of the homework so just aski开发者_C百科ng for a little help. I swear it's the wording that throws me off on these assignments almost as often as just learning the material itself.


I believe they want you to use the setter in order to set the year instead of setting the year directly.

public Undergrad(String inName, String inID, int inCredits,int inYear)
{
    super(inName, inID, inCredits);
    setYear(inYear);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消