| 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: 14672
|
|
|
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: 14672
|
|
And the next time you post some code, please UseCodeTags.
|
 |
 |
|
|
subject: java classes accessiblity
|
|
|