wood burning stoves 2.0
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Package question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Package question" Watch "Package question" New topic

Package question

John Blutarsky

Joined: Jun 24, 2005
Posts: 5
I have two files:

class PackageTest {
void MyPrint() {

class Test {
static public void main(String[] args) {
PackageTest pt = new PackageTest();

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

Joined: Sep 28, 2004
Posts: 1228
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 ]

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
I agree. Here's the link: http://aspose.com/file-tools
subject: Package question
It's not a secret anymore!