Forging The Rings!
From Huben's Wiki
Line 85: | Line 85: | ||
public Ring() | public Ring() | ||
{ | { | ||
− | + | this("iron", "a human King"); // calling the other constructor | |
} | } | ||
</pre> | </pre> | ||
− | Unless there are special circumstances, it is good style in Java to use the simplest way to accomplish a task, and that often means calling an existing method to accomplish most or all of the task for you. | + | The special way to call your own constructors is to use '''this''' as the first line of the constructor body. Not an obvious thing, so don't forget it. |
+ | |||
+ | Unless there are special circumstances, it is good style in Java to use the simplest way to accomplish a task, and that often means calling an existing method or constructor to accomplish most or all of the task for you. | ||
* Add this latter constructor to class Ring. | * Add this latter constructor to class Ring. |