• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class and method in same package?

 
shweta patiljadhav
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


in this code, is the testIt() method in the first file has default (think packagelevel)
access? class OtherClass is in a different package from the
AccessClass? how? could not get this....please explain....
 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shweta patiljadhav wrote:

in this code, is the testIt() method in the first file has default (think packagelevel)
access? class OtherClass is in a different package from the
AccessClass? how? could not get this....please explain....


The way I have it figured...testIt() has to be public, not default. Default would only be visible in the same package and you are dealing with two packages. Otherclass is a class in package certification. The same as ArrayList is a class in package java.util (java.util.ArrayList).

http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
http://www.cis.upenn.edu/~matuszek/General/JavaSyntax/import.html

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shweta patiljadhav wrote:in this code, is the testIt() method in the first file has default (think packagelevel)
access? class OtherClass is in a different package from the
AccessClass? how? could not get this....please explain....

Because OtherClass is in another package than AccessClass (the class accessing OtherClass), both OtherClass and its testIt method must be public, otherwise AccessClass will not compile.

Hope it helps!
Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic