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
Get step-by-step solutions from verified subject matter experts
