jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes To prove that methods can be overriden but attributes cannot be. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "To prove that methods can be overriden but attributes cannot be." Watch "To prove that methods can be overriden but attributes cannot be." New topic
Author

To prove that methods can be overriden but attributes cannot be.

Khuma Chhakchhuak
Ranch Hand

Joined: Nov 30, 2012
Posts: 34

I have run the following code (JunkFirst.java)in eclipse to prove that only methods can be overriden. It is throwing runtime exception "stackoverflow". How do I correct the error?


dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
You have an infinite recursion. In your definition of the class Child, you have an instantiation of that class. That means that any time you try to instantiate a new Child, that instance will instantiate a new Child, and then that instance will instantiate a new Child, and so and so on until the stack runs out of space.
Khuma Chhakchhuak
Ranch Hand

Joined: Nov 30, 2012
Posts: 34

Thanks Dennis.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: To prove that methods can be overriden but attributes cannot be.
 
Similar Threads
Overloaded methods
Confused for threading ?
Abstract class..
static methods and NULL
Map Problem