6 Replies Latest reply: Dec 4, 2007 7:06 AM by 807603 RSS

    Getting the name of a subclass?

    807603
      I'm writing this program for my computer science class and I was wondering if you guys could help me. I have a superclass called Person, with two subclasses, Student and FacutlyStaff.
      In my driver class, I have an array of Person objects. I need to print out each class types toString() method separately. For example, if the user chooses 1, I need to print out all the Student object's toString() method, and if the user chooses 2, the FacultyStaff object's toString() method. I know how to do everything (the user input, the array printing, etc.), I'm just having trouble finding out whether the object at the specific position in the array is a Student or a FacultyStaff object. I've tried records.getClass().getName(), but that always returns "Person"; and obviously because it is in a Person array.
      Help would be greatly appreciated!