Code: Select all
(obj instanceof A) && ! (obj instanceof C) && ! (obj instanceof D)
correctly identifies whether the object referred to by obj was created by instantiating class B rather than classes A, C and D?
Code: Select all
class A {}
class B extends A {}
class C extends B {}
class D extends C {}
This is one of the questions on the first exams from the software. Awesome test engine by the way...
Can someone explain to me how this expression is evaluated? Does the code 1) test (obj instanceof A) first then if this is true it 2) checks !(obj instance of C) and then when this returns false the code moves to the next line? I am confused by the combined && statements...
Also, I think it would need parentheses around the entire statement and should be preceded by an if keyword...