File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

class dependency problem.

Gene Woo

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:
------ ------
package example1;
public class A {

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

public static void main(String args)
A a = new A();
B b = new B();


--------- ------------
package example2;

public class B {

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


expired user

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