Search code examples
javainheritanceaccess-specifier

about understanding a java code segment from its design perspective


I am trying to understand a java-based open source project, which has a code segment like

protected SimpleBinaryModel(ExampleSet exampleSet, double threshold) {
    super(exampleSet);
    this.threshold = threshold;
}

Although I can generally guess how does this function aim to achieve, I do not quite understand the reason of defining this function as "protected" and defining "exampleSet" as "super". What are the general advantages of defining them this way from the perspective of OO design?

In addition, what doesthis.threshold = threshold; aim to achieve?


Solution

  • This is not a function. It's a constructor.

    super(exampleSet); means that a base class has a constructor with an ExampleSet parameter.

    And this.threshold = threshold; initialized the threshold field of the current class with the value of the parameter threshold.