aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Package Accessiblty problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Package Accessiblty problem" Watch "Package Accessiblty problem" New topic
Author

Package Accessiblty problem

Lucky J Verma
Ranch Hand

Joined: Apr 11, 2007
Posts: 278
i made a class MyClass ,put it in 1 package.
Using it in another class Test1 ,in another package.
like MyClass m=new MyClass();
its giving error ,
,MyClass is not public ,cant be access inotsside package.
I made MyClass public and even its constructr public ,which as not reqd.
what cud be the reason
dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
I am assuming that you have created MyClass's instance in Test1 class. As long as MyClass has default access modifier & both classes are in different packages, you can't access MyClass from Test1.
If you are not clear please post the exact code so that someone can reply you properly.


SCJP-1.5<br />SCWCD-1.4
Lucky J Verma
Ranch Hand

Joined: Apr 11, 2007
Posts: 278
MyClass is a public class,so must be accessible to any class.
I tried with its Constructor with public ..even.

MyClass ,Test1 Both are in different packages/
Test1 Class is using it ,MyClass ,but not accessible.

It cant be some older version prblem as MyClass was public for start only.
Youssef Ghazal
Greenhorn

Joined: May 27, 2007
Posts: 10
hi,
in order to use a public class outside the package that it had been created you have to import it ;


Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Howdy!

Youssef Ghazal posted Today 16:11

in order to use a public class outside the package that it had been created you have to import it


This seems to be one of the first postings of Youssef on this site, so


Welcome to the Ranch!





Maybe you found the cause why Lucky's code did not compile.
However, you cannot say that the import is absolutely required. Imports are only shortcuts for naming classes.

is just the same as




Yours,
Bu.


all events occur in real time
 
Don't get me started about those stupid light bulbs.
 
subject: Package Accessiblty problem