Why when I uncommenting toString it writes null?
<pre><code>import java.util.*;

public class Test {
    public static void main(String[] args) {

        List db = new ArrayList();

        ShopDatabase sb = new ShopDatabase(db);
        sb.addEntry(new ProductEntry("film", 30, 400));
        sb.addEntry(new CashierEntry("Kate", "Smith", 23, 600));
        sb.addEntry(new ManagerEntry("Jack", "Simpson", 1, 700));
        sb.addEntry(new ProductEntry("soap", 18, 3));
        sb.addEntry(new ManagerEntry("Helen", "Jones", 60, 650));
        sb.addEntry(new CashierEntry("Jane", "Tomson", 15, 900));
        sb.addEntry(new ProductEntry("shampoo", 25, 5));
        sb.addEntry(new CashierEntry("Bill", "Black", 59, 300));
        Collections.sort(db);
        Iterator itr = db.iterator();

        while (itr.hasNext()) {
            Entry element = (Entry) itr.next();
            System.out.println(element + "\n");
        }
    }
}

public abstract class Entry implements Comparable {

    public String name;
    public int id;

    public Entry(String name, int id) {
        this.name = name;
        this.id = id;
    }

    public String getName() {
        return this.name;
    }

    public int getId() {
        return this.id;
    }

    public int compareTo(Object entry) {
        Entry temp = (Entry) entry;
        int difference = this.id - temp.id;
        return difference;
    }

    public String toString() {
        return this.id + " " + this.name;
    }
}



public class People extends Entry {

    private String name;
    private String familyName;
    private int id;
    private int salary;

    public People(String name, String familyName, int id, int salary) {
        super(name, id);
        this.familyName = familyName;
        this.salary = salary;
    }

    /*
     * public String toString() { return this.id + " " + this.name + " " +
     * this.familyName + " " + this.salary; } /*public int compareTo(Object
     * entry) { Entry temp = (Entry) entry; int difference = this.id - temp.id;
     * return difference;
     * 
     * }
     */

}


public class ProductEntry extends Entry {

    public String name;
    public int id;
    public int stock;

    public ProductEntry(String name, int id, int stock) {
        super(name, id);
        this.stock = stock;
    }

    /*
     * public String toString() { return this.id + " " + this.name + " " +
     * this.stock; } /*public int compareTo(Object entry) { Entry temp = (Entry)
     * entry; int difference = this.id - temp.id; return difference;
     * 
     * }
     */
}



public class ManagerEntry extends People {

    public String name;
    public String familyName;
    public int id;
    public int salary;

    public ManagerEntry(String name, String familyName, int id, int salary) {
        super(name, familyName, id, salary);
    }
}



public class CashierEntry extends People {

    public String name;
    public String familyName;
    public int id;
    public int salary;

    public CashierEntry(String name, String familyName, int id, int salary) {
        super(name, familyName, id, salary);
    }

    /*
     * public String toString() { return this.id + " " + this.name + " " +
     * this.familyName + " " + this.salary; }
     */
}
</code></pre>

<p>Can anyone please help when I have code like this the output is </p>

<pre><code>1 Jack

15 Jane

18 soap

23 Kate

25 shampoo

30 film

59 Bill

60 Helen
</code></pre>

<p>but if I uncommenting toString in People and ProductEntry the output is </p>

<pre><code>0 null Simpson 700

0 null Tomson 900

0 null 3

0 null Smith 600

0 null 5

0 null 400

0 null Black 300

0 null Jones 650
</code></pre>

<p>why name and id is becomming null ???? Thank you in advance</p>
