0
public class MyResults extends Results {
    ...public MyResults() {
        this(5); 
    }
    public double average() {
        return this.getSum()/numberOfCourses; 
    }
}

What do both instances of ―this mean in the code?

  • 1
    There must be another constructor that takes (at least) a `int` parameter within the same class – MadProgrammer Oct 25 '18 at 05:40
  • 2
    it would be easier if you posted the code for the entire class, and it's parent. Long story short: the use of the keyword 'this' in this code, is exactly the same as in any other Java code – Stultuske Oct 25 '18 at 05:42

1 Answers1

1

First instance is a call to another constructor in the same class. This is also known as Constructor Chaining pattern. Since you didn't post the entire code we don't know if that other constructor is defined (it should be, otherwise you'll have a compile time error).

Second instance is a call to the getSum() method. This method might be defined either in MyResults class or Results class (or some parent class of Results, if any).