jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Where is the error? I don't understand!!! :( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Where is the error? I don Watch "Where is the error? I don New topic
Author

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

Shardul Kumar
Greenhorn

Joined: May 24, 2009
Posts: 12
here is the code: it gives compilation errors. why?

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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:


[Jess in Action][AskingGoodQuestions]
Chitta Ranjan Mahato
Ranch Hand

Joined: Jun 20, 2009
Posts: 38
You can not call a method within a method ,method body be declare out side the method
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Mar 05, 2008
Posts: 3003
    
    9
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

Joined: May 24, 2009
Posts: 12
Thankyou guys.
I've got the concept correctly.
Thanks again.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Where is the error? I don't understand!!! :(
 
Similar Threads
converting string array to string
Ugly Style !!
beans and jsp and not sure
Java Object assignment doubt.
Methods to access objects?