Results 1 to 7 of 7
  1. #1
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Post [SOLVED] How to link two different classes in the same package

    Hi pple,am a newbe to java.I have two different classes in the same package,the main class and another class.they are all running properly independently.HOW can i connect the two classes such that when i run the program,the other class is executed at a particular point in the program.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    becky is offline Member
    Join Date
    Jan 2009
    Posts
    13
    Rep Power
    0

    Default

    like Eranga said you have to instantiate your second class in the main class.
    for example:

    the name of the main class is: class_1.java
    the name of the second class is: class_2.java

    public class class_1{

    private class_2 c2; //c2 is an object of class_2

    public class_1() //constructor of class_1
    {
    c2=new class2(); //you create the object and call up the constructor of class_2
    }

    }

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Yep, this is only one way to do it, and much better way. But it's depends on the implementation you have follows. So the best thing our thread starter have to do is, read more about objects in Java.

    Classes and Object in Java, from Suns' Tutorial

  5. #5
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Default

    thanx alot.its working for me after reading this tutorial.
    Cheerz!!

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  7. #7
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Default

    Quote Originally Posted by Eranga View Post
    So please mark the thread solve.
    ok am goin to do tht

Similar Threads

  1. jsf command link
    By Srikala in forum JavaServer Faces (JSF)
    Replies: 2
    Last Post: 06-29-2010, 02:38 PM
  2. get classes of a certain package
    By ashraf shaban in forum New To Java
    Replies: 4
    Last Post: 07-08-2008, 07:20 PM
  3. Replies: 2
    Last Post: 07-04-2008, 12:33 PM
  4. Link for 64 bit JDK.
    By aparna in forum New To Java
    Replies: 0
    Last Post: 03-19-2008, 02:15 PM
  5. Replies: 1
    Last Post: 12-18-2007, 10:41 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
  •