Default class directly cannot be accessed through different package class .
It can be accessed only with in the package
but we have an option by calling default class from public class in same
package
and public class can allow to access default class from any other package.
Please check below code snippet.
Example :
*package a;
class DefaultPackageClass {
}
package a;
public class AcessDefaultClass {
DefaultPackageClass obj = new DefaultPackageClass ();
}*
*package b;
class AcessdefaultClassPackage {
**AcessDefaultClass obj = new **AcessDefaultClass ();
}*
2009/6/30 ρ Я д Ŧ έ e Қ ....Me |\|0T ThaT BaDD*** <[email protected]>
> class a { public void aFn() { System.out.println("Im in A"); } } class b {
> public void bFn() { System.out.println("I'm in B"); } public static void
> main(String args[]) { class a= new a(); a.aFn(); class b= new b(); b.bFn();
> } } the name of the file saved is b.java The output is Im in A Im in B My
> question is that how can we access other class as the default access
> specifier is package. we haven't imported the package. Please clear me
> through the concept of accessing a class .
> >
>
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---