0

So here is the problem. I have one array, there are two classes of object in it. Email which is the superclass and UniversityEmail which is the inheritance class. The array is of type Email. I wanna print out all the object of type Email from the array. Or print out UniversityEmail object based on a private variable extends by UniversityEmail class. Any idea?

1 Answer 1

1

Try the following:

for (int i = 0; i < array.length; i++) {
  if (array[i] instanceof Email) && (!(array[i] instanceof UniversityEmail)) {
    //print your object 
  }  
}

That's typed just from mind, so there might be some smaller issues.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.