• Post Reply Bookmark Topic Watch Topic
  • New Topic

Basic question on packages

 
Siva rarayana
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,
I have created following two classes and trying to compile.While compiling I am getting compilation errors.
Yax.java
--------
package abc.xyz;
public class Yax{
Nax n = new Nax();
public void abc()
{
System.out.println(" Yax");
}
}//eof Yax.java
Nax.java
----------
package abc.xyz;
public class Nax{
Yax n = new Yax();
public void abc()
{
System.out.println(" Nax");
}
}//eof Nax.java
the compilation command is
c:\test>javac -d . Yax.java
Now I am getting the following error
Yax.java:5: cannot resolve symbol
symbol : class Nax
location: class abc.xyz.Yax
Nax n = new Nax();
^
Yax.java:5: cannot resolve symbol
symbol : class Nax
location: class abc.xyz.Yax
Nax n = new Nax();
^
2 errors

If you compile with *.java it is ok.There will be no error.
please clarify it.
thankx and rgds,
siva
 
chi Lin
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Siva,
my 2 cents :
Have you put two files under the abc.xyz directory then compile the files ?

In the two files, your code creates a cause-result chain reaction between the two classes.
//when you compile either one of them, compiler looks for the other.
eg : when you compile Yax.java, compiler encounter Nax n = new Nax(); it then look for Nax inside the package you defined -> abc.xyz if compiler can not find Nax class it issue a error.

Originally posted by Siva rarayana:
Hi everybody,
I have created following two classes and trying to compile.While compiling I am getting compilation errors.
Yax.java
--------
package abc.xyz;
public class Yax{
Nax n = new Nax();
public void abc()
{
System.out.println(" Yax");
}
}//eof Yax.java
Nax.java
----------
package abc.xyz;
public class Nax{
Yax n = new Yax();
public void abc()
{
System.out.println(" Nax");
}
}//eof Nax.java
the compilation command is
c:\test>javac -d . Yax.java
Now I am getting the following error
Yax.java:5: cannot resolve symbol
symbol : class Nax
location: class abc.xyz.Yax
Nax n = new Nax();
^
Yax.java:5: cannot resolve symbol
symbol : class Nax
location: class abc.xyz.Yax
Nax n = new Nax();
^
2 errors

If you compile with *.java it is ok.There will be no error.
please clarify it.
thankx and rgds,
siva

[ January 30, 2003: Message edited by: chi Lin ]
 
John Paverd
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This will probably help you with your compile problems
Also, if you attempt to instantiate either Yax or Nax, the JVM will throw a java.lang.StackOverflowError, as the instance of the first class creates an instance of the other class, which creates an instance of the first class, which creates an instance of the other class...
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!