How to access information from a superclass and subclass?
<p>What I am trying to do is access information (variables, methods, etc) from a superclass and it's subclasses. </p>

<p>If, what I know about inheritance is right, by accessing the superclass we have access to it's subclasses by default. So I am thinking that I only need to be able to access the parent (super) class. </p>

<p>But how do I do that? </p>

<p>I am not going to post all the code up here, and that will turn this post into 3 pages. </p>

<p>The superclass is just a general code to create a contact and the class that needs to access the superclass is a class that creates an arraylist and records each contact in the arraylist.</p>

<p>I am not trying to get the code written for me, but all the help to understand how this will work, will be greatly appreciated. </p>

<p>To keep this short, I won't post the subclasses unless needed.</p>

<p>Contacts (Superclass):</p>

<pre><code>public class Contacts
{
    protected String fname;
    protected String lname;
    protected String email;
    protected String phone;

    public Contacts(String fname, String lname, String email, String phone)
    {
        this.fname=fname;
        this.lname=lname;
        this.email=email;
        this.phone=phone;

    }

    public String getfname()
    {
        return fname;
    }

    public void setfname(String first)
    {
        this.fname=first;       
    }

    public String getlname()
    {
        return lname;
    }

    public void setlname(String last)
    {
        this.lname=last;
    }

    public String getemail()
    {
        return email;
    }

    public void setemail(String e)
    {
        this.email=e;
    }

    public String getphone()
    {
        return phone;
    }

    public void setphone(String num)
    {
        this.phone=num;
    }

    public String getFullName()
    {
        String full=fname+" "+lname;
        return full;
    }
</code></pre>

<p>I haven't done much on this code because I have been trying to figure it out without really knowing where to start. I do not think the arguments should be null, I just included those to satisfy the evil compiler.</p>

<p>Addressbook:</p>

<pre><code>import java.util.ArrayList;
public class AddressBook
{
    Contacts enteredContact = new Contacts(null, null, null, null);
}
</code></pre>

<p>Here is one of the subclasses to get an idea of what is included.</p>

<p>Friends (subclass):</p>

<pre><code>public class Friend extends Contacts
{
    private String dob;

    /**
     * Constructs a new Friend object. (Insert any further description that is needed)
     * @param fname
     * @param lname
     * @param email
     * @param phone
     */
    public Friend(String fname, String lname, String email, String phone)
    {
        super(fname, lname, email, phone);
    }

    /**
     * @return the dob
     */
    public String getDob()
    {
        return dob;
    }

    /**
     * @param dob the dob to set
     */
    public void setDob(String dob)
    {
        this.dob = dob;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString()
    {
        return fname+", "+lname+", "+email+", "+phone+", "+dob;
    }

}
</code></pre>
