This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Mock Exam Errata and the fly likes some confusion about packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "some confusion about packages" Watch "some confusion about packages" New topic

some confusion about packages


Joined: Mar 16, 2001
Posts: 2


package Flora;
public class Tree {
protected int age;

import Flora.Tree;
public class Forest
public static void main (String s[]]
Tree t=new Tree();

u compile it compile nice.but u compile
it gives compile time error.

this two files are same package or not?
plz help me any one.
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
Your name doesn't comply with the naming standards here at Javaranch. Check out this link for more info:
Please re-register with a more appropriate name.
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
You classpath has to be setup so it knows where to find that package. Make sure your classpath includes the path to the package Flora.
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Sumanth,
In order for two files to be considered in the same package, you need to specify the exact same package line. In your file you have specified the line:
package Flora;
But in your you have not specified any package line. If you don't specify any package line then JVM uses default package. Therefore all files in same directory without package line in them will all be in the same package. To make your stuff work you can do 1 of 2 things.
1. Place line:
package Flora;
inside your file Your import line is then not required.
2. Place inside directory named 'Flora', set your classpath correctly, and then it should work.
Consider Paul's rocket mass heater.
subject: some confusion about packages
Similar Threads
Found a Bug In JDK 1.3.
Cannot find symbol
Help with Packages