Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-29-2004, 09:03 PM   #1
Registered: Jul 2003
Location: NSW. Australia
Distribution: Ubuntu, Fedora, Slackware
Posts: 181

Rep: Reputation: 30
how do you reload the 'main' method in Java?

Hi all,
I have a java program that is basically a menu. the user chooses an option, which takes them to another class that does various things. The when that class is finished its stuff, I want it to return to the original class with the'main' method in it and reload it, so that the user can choose another option, or choose the option to quit.

At the moment, once the second class is finished it just quits, but Ineed it to return to the original class and restart again.


public class original {

method here that displays a menu

another method that gets the value they enter

another method that calls the appropriate class depending on what they have entered.

public static void main(String args[]) {

call the three methods above, in order.


public class number1{

do some stuff

when done, return to original class, and reload 'main' // HOW?!?
please help!
Old 05-29-2004, 10:22 PM   #2
Registered: Aug 2003
Location: Planet Earth
Distribution: Linux Mint Debian Edition (LMDE)
Posts: 215

Rep: Reputation: 31
Well, you don't "call" a class. You call methods of a class. Your main method could be something like this:

public static void main( String[] args ) {

   number1 n1 = new number1();
   boolean done = false;
   int choice = 0;

   while ( !done ) {

      choice = getMenuChoice();

      switch ( choice ) {
         case 0 :
            done = true;
         case 1 :




Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
java newbie question method headers and if statements dflan98783 Programming 6 02-21-2007 11:18 PM
Method readLine() in KissDaFeetOfSean Programming 1 09-09-2005 12:41 AM
[java] Method signature precision pycoucou Programming 6 06-20-2004 11:31 AM
Java help (accessing array elemonts from another class or method) Tru_Messiah Programming 6 05-14-2004 09:20 AM
How to pass a file name into the main Method (C/C++) shassouneh Programming 2 06-20-2002 08:07 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:53 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration