• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Basic question on packages

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic