| Author |
instanceof operator
|
Lalit Sha
Greenhorn
Joined: Jan 11, 2001
Posts: 28
|
|
Could anybody explain the question below; Given the following class definitions, which expression identifies whether the object referred to by obj was created by instantiating class B rather than classes A,C and D? class A{} class B extends A{} class C extends B{} class D extends A{} Select all valid answers. a. obj instanceof B b. obj instanceof A && !(obj instanceof C) c. obj instanceof B && !(obj instanceof C) d. !(obj instanceof C) | | obj instanceof D e. !(obj instanceof A) && !(obj instanceof C) && !(obj instanceof D) thankx, Lalit.
|
 |
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
|
|
you have .A. | | B D | C a. is true but does not COMPLETELY identify B because it also fits C b. is not true because it also would work if obj was an A c. this is it  d. both B's and A's fit this. Actually D fits it also. e. a B has to be an instance of an A so this wouldn't work.
|
"JavaRanch, where the deer and the Certified play" - David O'Meara
|
 |
 |
|
|
subject: instanceof operator
|
|
|