Question: java Suppose classes A, B, C, D, and E all extend class Top. Suppose also that classes A, B, and C also implement the interface

java

Suppose classes A, B, C, D, and E all extend class Top. Suppose also that classes A, B, and C also implement the interface Face. Now, suppose we also have an ArrayList of type Top named myList that contains instances of classes A, B, C, D, and E, and we wish to iterate through this list to pick out only the instances of classes A, B, and C. We consider the following ways to test each instance x in myList to do this:

(i) if( x instanceof A || x instanceof B || x instanceof C ) { ...
(ii) if( x instanceof Face ) { ...

Which of these ways will work to identify instances of classes A, B, and C, but not D or E?

Only choice (ii) will work.
Both ways will work.
Only choice (i) will work.
Neither way will work.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!