This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes method problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "method problem" Watch "method problem" New topic
Author

method problem

salvador rcn
Ranch Hand

Joined: Feb 18, 2004
Posts: 51

i want to know whats wrong in this code ?
// line 1
is it possible to write a method which is not a member function using public modifier ?
untill unless i call(invoke) a method , can a method be excuted ?
why the code is wrong ?
i did not want to print the values of "i" . but i did to see whther it executes if i dont call it. but got error
Carlos Failde
Ranch Hand

Joined: Oct 20, 2000
Posts: 84
You have written a method called start() inside a method called main(). You can not nest methods like that.
You want to write something like:

A method is only executed when it is invoked.
is it possible to write a method which is not a member function using public modifier ?

I am not sure what you are asking here. I think you may be referring to static methods, so rewriting start to be static means just inserting the static keyword:

Then in main in can be invoked without an instance of the class:
start()
OR
Bground.start();
Hope that clears things up.
salvador rcn
Ranch Hand

Joined: Feb 18, 2004
Posts: 51
thanks ...i have understood it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: method problem