I wrote a program consisting of 3 classes and a main class, the 3 classes going through inheritance chain(Employee, Teacher extends Employee, MathTeacher extends Teacher). I've constructed an ArrayList for employees. so I'm trying to call a method from the MathTeacher class in the main class (concerning the ArrayList) but I can call nothing but the Employee class methods . any advice?
Edit: I'm undergraduate, new to the Inheritance chapter.
By typecasting an item from the array into the MathTeacher object, you can use the methods from this class, not just those from Employee. For example:
((MathTeacher) arrayList.get(0)).mathTeacherMethod();
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments