How to use several separate classes (separate files) to be executed in one class (another file)

Discussion in 'Java' started by EvgueniB, Dec 15, 2003.

  1. EvgueniB

    EvgueniB Guest

    Hi,
    Looking for an example, where couple separate classes in separate files will
    be attached and used (executed) in new class in separate file.

    Thanks in advance!!!
     
    EvgueniB, Dec 15, 2003
    #1
    1. Advertising

  2. "EvgueniB" <> wrote in message
    news:gi7Db.53670$...
    > Hi,
    >
    > Looking for an example, where couple separate classes in
    > separate files will be attached and used (executed) in new
    > class in separate file.
    >


    // *** Separate Package ***

    javac xx/A.java
    javac xy/B.java
    javac xz/UseAndB.java
    java xz.UseAndB

    // File: A.java
    package xx;
    public class A { public void doA() {}}

    // File: B.java
    package xy;
    public class B { public void doB() {}}

    // File: UseAandB.java
    package xz;
    import xx.A;
    import xy.B;

    public class UseAandB
    {
    public static void main(String[] args)
    {
    A a = new A(); a.doA();
    B b = new B(); a.doB();
    }
    }

    // *** Same Package ***

    javac xp/UseAndB.java
    java xp.UseAndB

    // File: A.java
    package xp;
    public class A { public void doA() {}}

    // File: B.java
    package xp;
    public class B { public void doB() {}}

    // File: UseAandB.java
    package xp;
    public class UseAandB
    {
    public static void main(String[] args)
    {
    A a = new A(); a.doA();
    B b = new B(); b.doB();
    }
    }

    I hope this helps.

    Anthony Borla
     
    Anthony Borla, Dec 15, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GG
    Replies:
    17
    Views:
    603
    P.Hill
    Feb 17, 2006
  2. Frank Fredstone
    Replies:
    1
    Views:
    459
    Jean-Francois Briere
    Jun 27, 2006
  3. Replies:
    4
    Views:
    1,267
    Daniel Pitts
    Nov 8, 2008
  4. Zev Blut
    Replies:
    10
    Views:
    185
    Zev Blut
    Feb 23, 2005
  5. Victor \Zverok\ Shepelev

    RDOC: several related modules in several C files

    Victor \Zverok\ Shepelev, Mar 6, 2007, in forum: Ruby
    Replies:
    3
    Views:
    188
    Max Lapshin
    Mar 16, 2007
Loading...

Share This Page