| Author |
package problem
|
dimpsonu arora
Ranch Hand
Joined: Aug 13, 2003
Posts: 51
|
|
Hi All, I am making two directories pack2 and pack3 under c:/java/pack1. The directory structure is: c:/java/pack1/pack2/abc.java c:/java/pack1/pack3/hello.java 1.c:/java/pack1/pack2/abc.java ***********abc.java********** package pack1.pack2; public class abc { public void abc() { System.out.println("Hello I am ABC."); } } 2.c:/java/pack1/pack3/hello.java *********Hello.java********* package pack1.pack3; import pack1.pack2.*; public class hello { public static void main(String args[]) { abc obj=new abc(); obj.abc(); System.out.println("Hello World"); } } When I try to compile hello.java it gives compilation error at import pack1.pack2.*; does not exist. Plz help..............
|
 |
Chinmay Bedarkar
Greenhorn
Joined: Apr 20, 2004
Posts: 3
|
|
compile ur code from c:\java as c:\java>javac -d . pack1\pack2\*.java pack1\pack3\*.java this will compile the 2 classes. To run hello.java, stay in c:\java and run it as c:\java>java pack1.pack3.hello this should work well.
|
 |
Sandeep Jindal
Ranch Hand
Joined: Aug 25, 2003
Posts: 180
|
|
in addition to what Chinmay has said, instead of compiling all the files/packages separately, u can compile one main/parent file, it will automatically compile all the dependent files. So your command can be : c:\java>javac pack1\pack3\hello.java c:\java>java pack1.pack3.hello [ July 01, 2004: Message edited by: Sandeep Jindal ]
|
SCJP 5.0
http://sites.google.com/site/duddlutechnologies/home
|
 |
Anton Golovin
Ranch Hand
Joined: Jul 02, 2004
Posts: 473
|
|
|
You named a method in your abc class the same as the class, which is only reserved for constructors (which may not have the void key word.)
|
Anton Golovin<br /><i>anton.golovin@gmail.com</i><br />SCJP, SCJD, SCBCD, SCWCD
|
 |
K Anshul
Ranch Hand
Joined: May 19, 2004
Posts: 71
|
|
Originally posted by Anton Golovin: You named a method in your abc class the same as the class, which is only reserved for constructors (which may not have the void key word.)
You may name a method same as the name of the class but it is not a good practice at all.
|
 |
 |
|
|
subject: package problem
|
|
|