• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method problem

 
salvador rcn
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks ...i have understood it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic