I have an abstract User class, a user can be created either as a Student type or as a Teacher type. I made an ArrayList of users (students and teachers), and what I'm trying to do is to call an example method depending on who the current object is:
for (User user : listOfUsers) { String name = user.getName(); if (user instanceof Student) {
The problem I encountered is that these are ArrayList User objects, it cannot get a method like Student, like getGrade (). However, since I can determine who the current user is, I am curious if a particular method can still be called depending on what type of user it is.
Is this possible, or do I need to separate user types into separate lists?
Answer soon, thank you very much.
source share