aspose file tools*
The moose likes Java in General and the fly likes java classes accessiblity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "java classes accessiblity" Watch "java classes accessiblity" New topic
Author

java classes accessiblity

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

using jcreator

i made 2 classes in java
test.java
UseMeTest.java
saved both in the same folder

--------Test.java---------
public class Test
{
public static void main(String arg[])
{
UseMeTest ob=new UseMeTest();
System.out.println(ob.a);
}
}



-------UseMeTest.java----------


class UseMeTest
{
int a=10;
}



both the java are compling fine
and the output of Test.java is
10


i think this is wrong . i mean to say is that how could a class access other class object as i did not put them in same package neither the UseMeTest.java class is declared as public


OCPJP 6.0 93%
OCPJWCD 5.0 98%
Dawn Charangat
Ranch Hand

Joined: Apr 26, 2007
Posts: 249
You mentioned that you placed both classes in the same directory - that means they share the same package.
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

both the classes are in the same folder but i have not used any package statement in my code.
is there some default package created ?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Yes. If you don't put them in a package, they'll be in the so-called default package. You should avoid that, and always put classes in packages.


[My Blog]
All roads lead to JavaRanch
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

And the next time you post some code, please UseCodeTags.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java classes accessiblity
 
Similar Threads
Two public classes in a file
An interesting Question on default constructor
//Comment in java
Compiling two public scope java classes in a .java file
NoSuchMethodError