Default

When no access modifier is specified for a class , method or data member, it is said to be having the default access modifier by default. The data members, class or methods which are not declared using any access modifiers i.e. having default access modifier are accessible only within the same package. In this example, we will create two packages and the classes in the packages will be having the default access modifiers and we will try to access a class from one package from a class of second package. The tree structure of the directory (in Windows) is as follows:


\begin{lstlisting}
E:\work\java\eclipse\HelloWorld\src>dir
Volume in drive E has...
...r
1 File (s) 179 bytes
4 Dir ( s) 85 ,037 ,547 ,520 bytes free
\end{lstlisting}

If you see carefully I am inside a project HelloWorld and I have one .java file besides two folders namely p1 and p1, these two folders represents two different packages (ala package1 p1 and package2 p2 ). I will develop two classes namely A and B. The code is as follows:


\begin{lstlisting}
// package p1
package p1 ;
\par
public class A {
public void ...
...] args){
A obj = new A () ;
obj . display () ;
display () ;
}
}
\end{lstlisting}

Do experiments by pricking out modifiers i.e., public from where it is and try to experiment in Eclipse to know about errors. Eclipse gives immediate error messages the moment the modifier is deleted from either class or method.