I've been looking around and even though I have found some answers for some reason I can't seem to grasp the concept which is obviously causing a problem in my code.
I have this:
public static Contact createContact() {
Contact contact = null;
if (ContactUI.getRdb_acquaintance().isSelected()) {
contact = new Acquaintance();
} else if (ContactUI.getRdb_friend().isSelected()) {
contact = new Friend();
//contact.setStr_telMobile(ContactUI.getTxt_telMobile().getText());
} else {
contact = new Family();
//contact.setStr_telMobile(ContactUI.getTxt_telMobile().getText());
//contact.setStr_BDay(ContactUI.getTxt_BDay().getText());
}
setCommonDetails(contact);
return contact;
}
What I would like is to be able to call the subclasses specific methods .setStr_telMobile and .setStr_BDay once I have initialized contact as one of its subclasses, but I get an error, I can't access those methods. I have commented the lines in my code.
I thought I was supposed to be able to initialize an object of type Contact to a Friend (subclass of Contact), for example, and get access to the subclass specialized methods and attributes.