aspose file tools
The moose likes Beginning Java and the fly likes instanceof operator Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "instanceof operator" Watch "instanceof operator" New topic
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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: instanceof operator
 
Similar Threads
instanceof prblem help me
Q35-mock exam from PJ
Doubt in instanceof operator
operator instanceof confusion
PGJC mock exam question