wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Basic question on packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Basic question on packages " Watch "Basic question on packages " New topic
Author

Basic question on packages

Siva rarayana
Greenhorn

Joined: Jan 30, 2003
Posts: 1
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

Joined: Aug 24, 2001
Posts: 348
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 ]

not so smart guy still curious to learn new stuff every now and then
John Paverd
Ranch Hand

Joined: Nov 17, 2002
Posts: 115
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...


SCJP 1.4
 
 
subject: Basic question on packages