Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><em>First I need to overload the constructor by adding a default (no-args) constructor to Person that defines an object to have the name "N/A" and an id of -1.</em></p> <p>Read about constructors <a href="http://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html" rel="nofollow">here</a>.</p> <p>The Person class already contains a ctor that takes 1 argument. What you need to do is create a "default ctor" which is typically a ctor w/out any parameters.</p> <p>Example:</p> <pre><code>class x { // ctor w/ parameter // x(int a) { // logic here } // default ctor (contains no parameter) // x() { // logic here } } </code></pre> <p><em>Then i need to add a setter method named reset that can be used to reset the two private instance variables of this class to two values passed in as parameters.</em></p> <p>Setter methods are used to "encapsulate" member variables by "setting" their value via public function. See <a href="http://docs.oracle.com/javase/tutorial/reflect/member/fieldValues.html" rel="nofollow">here</a>.</p> <p>Example:</p> <pre><code>class x { private int _number; // Setter, used to set the value of '_number' // public void setNumber(int value) { _number = value; } } </code></pre> <p><em>Then I need to add a getter method named getName and getId that can be used to retrieve these two private variables</em></p> <p>Getters do the opposite. Instead of "setting" the value of a private member variable, they are used to "get" the value from the member variable.</p> <p>Example:</p> <pre><code>class x { private int _number; // Getter, used to return the value of _number // public int getNumber() { return _number; } } </code></pre> <p>Hope this helps</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload