I have this super class named Person which is inherited by two other classes, Employee & Client I am using an interface so as I can use generics on the two sub classes and hence the Person class implements this interface, Searchable. Is it possible for the Person class to implement both the interface and Serializable so I can save?
package compuwiz;
public abstract class Person implements Searchable //implements Serializable ??
{
public Person()
{
pName = "";
pSurname = "";
pIdCard = "";
}
public Person(String nm, String sn, String id)
{
pName = nm;
pSurname = sn;
pIdCard = id;
}
String pName;
String pSurname;
String pIdCard;
public String GetName()
{
return pName;
}
public String GetSurname()
{
return pSurname;
}
@Override
public String GetID()
{
return pIdCard;
}
//Set Methods
public void SetName(String nm)
{
pName=nm;
}
public void SetSurname(String sn)
{
pSurname=sn;
}
public void SetID(String id)
{
pIdCard=id;
}
@Override
public String ToString()
{
return this.GetName()+ " " +this.GetSurname()+ "ID card number:" +this.GetID();
}
Yes. That's the purpose of interfaces. A class can implement multiple interfaces at the same time:
Besides this, I would recommend using proper naming of your methods. This is, use
camelCase
standard, the first letter goes in lower case, then you use upper case for the next word contained in the name. Example:To