Results 1 to 7 of 7
  1. #1
    AkwardTurtle is offline Member
    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    Default Problems with Class

    Hello Guys!

    My question is quite simple. I have two classes in java. One class runs properly, but does not display anything to the user. When I run this class it jumps to the other class, which does display something to the screen. How do I stop this from happening?

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,414
    Rep Power
    5

    Default Re: Problems with Class

    Please post an example (preferably an SSCCE - see link in signature below).

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    AkwardTurtle is offline Member
    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    Default Re: Problems with Class

    First class that's not suppose to display anything:

    public class IfelseStatements
    {
    public static void main(String args)
    {

    boolean test = false;

    if(test)
    {
    System.out.println("test is true");
    }

    }
    }

    Second class it keeps jumping to:

    public class Programming
    {
    public static void main(String[] args)
    {
    int answer = add(10,5);

    System.out.println("The answer is " + answer);
    }

    static void print(String s)
    {
    System.out.println("s");
    }

    static int add(int a, int b)
    {
    int c = a + b;
    return c;
    }

    }

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,414
    Rep Power
    5

    Default Re: Problems with Class

    The one which will run is the one with the public static void main(String[] args) entry point. Notice in the other class, main does not have an array as an argument.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Problems with Class

    As mentioned above the IfelseStatements class does not have a proper main method so you cannot run it and therefore it cannot "jump" to the other class. You must be running the other class in the first place.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: Problems with Class

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    AkwardTurtle is offline Member
    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    Default Re: Problems with Class

    Ok. Thank you for your assistance.

Similar Threads

  1. Replies: 6
    Last Post: 02-08-2012, 06:42 PM
  2. Problems casting with the same class
    By johnwcv in forum Advanced Java
    Replies: 4
    Last Post: 03-22-2011, 01:36 PM
  3. class loader problems!
    By alacn in forum New To Java
    Replies: 6
    Last Post: 08-11-2010, 10:51 PM
  4. Inner class problems
    By orchid in forum New To Java
    Replies: 2
    Last Post: 08-13-2008, 08:56 AM
  5. Scanner class problems
    By sypherz in forum New To Java
    Replies: 6
    Last Post: 06-09-2008, 09:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •