Results 1 to 7 of 7
  1. #1
    Tony Stark is offline Member
    Join Date
    Aug 2016
    Posts
    26
    Rep Power
    0

    Default Running two classes at once

    i have done a program with two classes sth like get your name and age and print them using objects , i can run the two classes together using Eclipse , but can i do this using Cmd ?
    i mean can i compile two classes at once and run them using java and javac and how ?
    or i will need to mix them together into one class ? how ? .

    thanks
    Tony.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Running two classes at once

    You can do it either way (and I recommend you do both for practice). The JRE will find the classes as they need to be accessed.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Tony Stark is offline Member
    Join Date
    Aug 2016
    Posts
    26
    Rep Power
    0

    Default Re: Running two classes at once

    ok you mean that if i compile the main class using cmd and javac the two classes will be compiled automatically ? .
    and how i can mix two classes into one class using Eclipse ? .

    thanks .
    Tony .

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Running two classes at once

    Quote Originally Posted by Tony Stark View Post
    ok you mean that if i compile the main class using cmd and javac the two classes will be compiled automatically ?
    Only if they are in the same file. Otherwise you need to compile them separately (or use some build tool).

    and how i can mix two classes into one class using Eclipse ?
    I am not certain what you mean when you say mix. Putting two classes together in the same file or referencing one from the other?
    To combine two classes into one you just refactor or cut and paste. To make use of the classes you just create an instance of one class
    from the other and use it.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    Tony Stark is offline Member
    Join Date
    Aug 2016
    Posts
    26
    Rep Power
    0

    Default Re: Running two classes at once

    to be honest , what the hell are you talking about ? :D .
    How can i put two classes in one file so i can compile it once using cmd , and what do you mean by "build tool" ? :D

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Running two classes at once

    Quote Originally Posted by Tony Stark View Post
    to be honest , what the hell are you talking about ?
    First, any form of profanity is not permitted in this forum and, if continued, could result in you being
    banned.

    How can i put two classes in one file so i can compile it once using cmd
    You know how to put in a single class, right? Then just put one or more in right after it. Same syntax
    but omit the static main entry point. Add whatever fields and methods you want.

    Java Code:
    class One {
    }
    
    class Two{
    }
    etc.

    and what do you mean by "build tool" ?
    https://en.wikipedia.org/wiki/List_o...ation_software

    You need to get a book and read about Java and/or take some tutorials. Click on the
    link in my signature below.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  7. #7
    Tony Stark is offline Member
    Join Date
    Aug 2016
    Posts
    26
    Rep Power
    0

    Default Re: Running two classes at once

    Thanks , i'm really sorry i did not mean anything wrong forgive me :(

Similar Threads

  1. Replies: 5
    Last Post: 05-21-2014, 01:50 PM
  2. Replies: 7
    Last Post: 12-18-2011, 04:13 AM
  3. Replies: 0
    Last Post: 08-26-2009, 01:03 PM
  4. Running java classes with XML
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 06-29-2007, 03:20 PM

Posting Permissions

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