• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Package question

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic