• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

instanceof doubt

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,




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


Thanks in Advance
samura

 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



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 ]
 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Akhilesh Trivedi
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



Thanks Akhilesh!


regards
samura

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic