Hi,
Don't know where these are but
StudentRecord annaRecord = new StudentRecord("Anna", 10, 20, 30,
*annaRecord.getAverage()*);
*but after it, it shwos the error that " variable annaRecord might not
have been initialized ".*
Your error is given by the code in red. You have not yet constructed
annaRecord but you are using *annaRecord.getAverage()* function.
In other words, you are constructing annaRecord with a function call on
annaRecord. This gives the error.
When you made all static and using StudentRecord.getAverage() you get all
built in types with default value. This is wrong because the you made all
fields static. When you are declaring second student ALL PREVIOUS STUDENT
GRADES ARE LOST (remember, static is common for all objects).
*average = 0.0* is because where you are not initializing built in types,
they have a default value in Java(numerics are 0 or 0.0 and boolean is
false).
Yes, the exercise seems odd but you could do this.
StudentRecord annaRecord = new StudentRecord("Anna", 10, 20,
30,(10+20+30)/3);
This gives you no error and you preserve each student grades (they are
private for each student)
Best regards,
Vasile Braileanu
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---