“The strongest of all warriors are these two — Time and Patience.” ― Leo Tolstoy, War and Peace
DittoPete Letkeman wrote:Welcome to CodeRanch . . .
Yes, you can. But you should only call methods marked final or private from the constructor.You cannot access instance methods from within a constructor. . . .
Campbell Ritchie wrote:Yes, you can. But you should only call methods marked final or private from the constructor.
“The strongest of all warriors are these two — Time and Patience.” ― Leo Tolstoy, War and Peace
Pete Letkeman wrote:If you do use super() then it must be the first line of the constructor.
Campbell Ritchie wrote:OP: The reason you were getting a null pointer exception is that you were trying to use an uninitialized field. I wouldn't call that a minimal error, though you are right that its solution is straightforward.
Stephan van Hulst wrote:https://coderanch.com/t/682106/java/constructor#3199923
(1) don't pass 'this' to methods of other classes,
(2) don't call methods of the current class unless they are private, final or static
(3) don't start new threads, and
(4) don't call private, final or static methods that indirectly do any of the previous three points.
okli okim wrote:highlighted in red and a light bulb will suggest an autofix
“The strongest of all warriors are these two — Time and Patience.” ― Leo Tolstoy, War and Peace
Knows about | |
---|---|
Model | Model |
View | Model, View |
Controller | Model, View, Controller |