File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Package question

 
John Blutarsky
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two files:

File1.java:
class PackageTest {
void MyPrint() {
System.out.println("Hello");
}
}

File2.java:
class Test {
static public void main(String[] args) {
PackageTest pt = new PackageTest();
at.MyPrint();
}
}

It's compile fine.
Why? I don't specify nothing about "package". How File2 views File1, there isn't package keyword.

Thanks. (sorry for my english)
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code compiles & runs because both these classes are in the same folder ( To be more correct both classes are added to the class path ). Try to put the other class some where else and add this class ( with the whole path ) to the class path , even then you should be able to run the program.

When we give a Package statement, we are logically grouping related classes to be in one folder. This is for code readability & for easy maintenance.
[ October 13, 2005: Message edited by: Srinivasa Raghavan ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic