Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Package Accessiblty problem

 
Lucky J Verma
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
  • 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
 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Youssef Ghazal
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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 ;


 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic