File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes instanceof doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "instanceof doubt" Watch "instanceof doubt" New topic
Author

instanceof doubt

aslika bahini
Ranch Hand

Joined: Mar 03, 2007
Posts: 111
Hi,




can any explain why the above code throws exception
(Exception in thread "main" java.lang.StackOverflowError)


Thanks in Advance
samura

Manfred Klug
Ranch Hand

Joined: Jun 04, 2007
Posts: 377
Hi samura,

the problem is the b variable in BinstanceTest. When you instantiate a BinstanceTest, a second BinstanceTest is instantiated to initialize the b variable which instantiates a BinstanceTest to initialize the b variable which ...
aslika bahini
Ranch Hand

Joined: Mar 03, 2007
Posts: 111


Thanks Manfred,




Operands and Results Using instanceof Operator

In pg 286 (k&B book) table 4.1

I didn't get the 5th row..

1st operand = Foo[]
instanceof operand = Foo,Bar,Face
result = false

why the result is false?

Thanks!
samura





[ August 23, 2007: Message edited by: samura babu ]
[ August 23, 2007: Message edited by: samura babu ]
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1535
First operand is an array of object and second operand is the object itself.

MyClass obj;
MyClass arrObj[];

You can not compare obj with arrObj. However comparison between "arrObj[someIndexHere]" and "obj" would be legal.
[ August 23, 2007: Message edited by: Akhilesh Trivedi ]

Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1535
Originally posted by Manfred Klug:
Hi samura,

the problem is the b variable in BinstanceTest. When you instantiate a BinstanceTest, a second BinstanceTest is instantiated to initialize the b variable which instantiates a BinstanceTest to initialize the b variable which ...


That was really deadly manfred, good catch.

Samura! Good practice would be to have member variable declarations in the class, and initializations at the place/constructor/methods where they are necessary.
aslika bahini
Ranch Hand

Joined: Mar 03, 2007
Posts: 111


Thanks Akhilesh!


regards
samura
 
Don't get me started about those stupid light bulbs.
 
subject: instanceof doubt