Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

instanceof

 
K Anshul
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


But C option states that obj is an instance of B and obj is not an instance of D.
What about obj being an instance of A.
Even in that case obj instanceof B will return true. But the question mentions that obj must have been created by instatiating B and not A,C,D.
But with C option we can't be sure if obj was created from A or B.

Edited by Corey McGlone: Removed lengthy line of CODE to preserve formatting.
[ June 23, 2004: Message edited by: Corey McGlone ]
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and? what's the problem?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Prints false
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if you try to create obj as a B from an A, like this:

B obj = (B)new A();

then that statement itself causes a ClassCastException at runtime.
[ June 23, 2004: Message edited by: Barry Gaunt ]
 
K Anshul
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Barry Gaunt:


Prints false


But this prints true

 
K Anshul
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From what i could understand from this question it states that object was created by instantiating B.
and then it says how will u find out that object was created by instantiating B and not A, C, D.
Plz correct me if i am wrong.
[ June 23, 2004: Message edited by: Anshul Kayastha ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic