File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes class dependency problem. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "class dependency problem." Watch "class dependency problem." New topic
Author

class dependency problem.

Gene Woo
Greenhorn

Joined: Mar 17, 2001
Posts: 3
Hi, there.
I am working on project that has many objects that have cross dependency problem, for example. A calls B and B class A. As a result, many objects can't compile if they are not in the same package. is there a way where I can get the classes to compile without change many lines of code. for example:
------ A.java ------
package example1;
public class A {

public void printB()
{
System.out.println("In printB: ");
B b = new B();
b.printA();


}
public static void main(String args)
{
A a = new A();
a.printB();
B b = new B();
b.printA();

}

}
--------- B.java ------------
package example2;

public class B {

public void printA()
{
System.out.println("In printA: ");
A a = new A();
a.printB();


}
}

-----------------------------------------
expired user
Greenhorn

Joined: Dec 13, 2001
Posts: 11
I suppose that u have to import the packages inorder to access the class and in turn the methods defined in those classes. Without importing Java doesn't know anything about the class A or B, in your case.
Try with this
import package.class;
import package.*;
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: class dependency problem.
 
Similar Threads
a problem of multiple inheritance
Circular Redundancy in Java
Anonymous inner class
Confused with static methods
which is the best way