• Post Reply Bookmark Topic Watch Topic
  • New Topic

Compilation of code  RSS feed

 
Mahesh x Bogadi
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 2 classes in 2 different files say

public class A {

public void methodA() {
B b = new B();
b.methodB();
}
}

public class B {
public void methodB() {
A a = new A();
a.methodA();
}
}

How to compile these two files?
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javac A.java
or
javac Beginner.java
 
Mahesh x Bogadi
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not still working
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
circular dependencies... It needs A.class to compile B.class and needs B.class to compile A.class.

You won't be able to call either A.methodA or B.methodB even if you get it to compile without running out of stackspace (and/or heapspace, whichever runs out first) anyway because you're going to get infinite nested object instantiations.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well - I compiled it without problems with java1.5.0-beta3 on linux.
 
J�rg Vater
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I compiled it without problems with java1.3.1_03 on Win2000.

put both files (A.java and B.java) in a directory and then javac * and that's it

Is this the right place for this question? I would move this to Java(beginner)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!