• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Where is the error? I don't understand!!! :(

 
Shardul Kumar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is the code: it gives compilation errors. why?

 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method "method" is defined inside the method "main". You can't do that; move all of "method" outside of the body of "main". You'd have to move "str" out to the body of the class so that "method" could see it, make "str" and "method" static so that "main" can see it, and then call mehtod() from main. Altogether, it could look something like:
 
Chitta Ranjan Mahato
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can not call a method within a method ,method body be declare out side the method
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chitta Ranjan Mahato wrote:You can not call a method within a method ,method body be declare out side the method

You mean you cannot *declare* a method within a method.
 
Mike Simmons
Ranch Hand
Posts: 3040
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chitta Ranjan Mahato wrote:You can not call a method within a method


I think you mean that you can not declare a method directly* within another method. It's certainly possible to call another method though. This is probably just a linguistic misunderstanding, but I think it's important to correct in this case.

declaring a method != calling a method

* It's possible to declare an inner class within a method, and then declare another method within that inner class. But that's a more advanced topic, and not what the original poster was doing.

I see David has already posted as much while I was dealing with posting problems. Oh well - I hope the added detail here may help some.
 
Shardul Kumar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou guys.
I've got the concept correctly.
Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic