• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is the code: it gives compilation errors. why?

 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can not call a method within a method ,method body be declare out side the method
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Master Rancher
Posts: 4796
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankyou guys.
I've got the concept correctly.
Thanks again.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic