There is a lot of confusion about the difference between constructors and methods. One difference you won't understand is that methods are members of a class and constructors aren't.
You can call a method as many times or as few times as you like; you call a constructor once for each object, immediately after that object has been created. Methods always have return types (or void) and constructors never do.
I shall let you find out what happens if you mistakenly give a constructor a return type.But constructors aren't methods and methods aren't constructors.
Campbell Ritchie wrote:We don't have the time to go through every tutorial on YouTube, but I have seen very few that I would describe as good. Most that I can remember miss out so much that they are only of use to experienced people
Please provide a link to that tutorial, but I can't promise to view it.
Where did you find a description of those concepts?
There used to be a party trick with a static initialiser and System.exit() which ran without a main() method, but it hasn't worked since Java7.
Norm Radder wrote:
why does it give me "true"??
Look at the API doc for the Hashset add method, it says:
Returns:
true if this set did not already contain the specified element