Find errors. If name is a String instance variable, average is a double instance
ID: 3631074 • Letter: F
Question
Find errors.If name is a String instance variable, average is a double instance variable, and numOfStudents is a static int variable, why won’t the following code from a class compile?
public Student(String s)
{
name = s;
average = getAverage(name);
numOfStudents++;
}
public double getAverage(String x)
{
numOfStudents++;
double ave = StudentDB.getAverage(x);
return ave;
}
public static void setAverage(double g)
{
average = g;
}
a. The constructor can’t increment the numOfStudents variable.
b. The getAverage method can’t increment the numOfStudents variable.
c. The getAverage method can’t call a static method in the StudentDB class.
d. The setAverage method can’t access the average instance variable.
Explanation / Answer
the getAverage method can’t increment the numOfStudents variable.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.