• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Package Accessiblty problem

 
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Lucky J Verma
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
in order to use a public class outside the package that it had been created you have to import it ;


 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic