Thank you.

Now I find this constructor redundant.
// Redundant? I cannot pass the average argument here.
StudentRecord annaRecord=new StudentRecord("Anna",90,91,92,0);
double avg=annaRecord.getAverage();

// This would accomplish the same. Use the other constructor.
StudentRecord annaRecord=new StudentRecord("Anna",90,91,92);
double avg=annaRecord.getAverage();

On Feb 27, 5:54 pm, miga <[email protected]> wrote:
> On Feb 27, 10:11 am, [email protected] wrote:
>
> > In StudentRecord.java: I overloaded a constructor like this:
> >     public StudentRecord(String name,double mathGrade,double
> > engGrade,double sciGrade,double avg){
> >         this(name,mathGrade,engGrade,sciGrade);
> >         average=avg;
> >     }
>
> > In ConstructorExample.java: I tried to create annaRecord object like
> > this:
> > // Wrong. How?
> > StudentRecord annaRecord=new StudentRecord("Anna",
> > 90,91,92,annaRecord.getAverage());
>
> You cannot pass the constructor a function based on the parameters of
> the constructor, as the object is not already constructed, hence you
> have no access to the fields.
> You should pass a double value as average value, just as you passed
> double value for mathGrade, etc.
> Then, once the object is built, you may access the getAverage method.

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to