Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Khuma Chhakchhuak
Ranch Hand
Posts: 37
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 808
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dennis.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic