File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""protected" access specifier" Watch ""protected" access specifier" New topic
Author

"protected" access specifier

nirjari patel
Ranch Hand

Joined: Apr 23, 2009
Posts: 374
If I have created a class "testSpecifier1.java" with access specifier as protected , in package testClasses, I can access this class anywhere in same package.
I have to import package in a class to use content from that package. So if I create another class "testSpecifier2.java" in the same package testClasses, do I need to import this package in the beginning of the coding ? Or can I access content within same package without importing package ? How doea this work with static methods ? As static methods dont need the class to be instantiated. If I dont need to import package to be imported for use in another class within same package, what if there are two static method by the same name in two different classes ? Do I need to specify class name before the static method name in order to specify what static methid I want to use ? If there is unique static method in a class which is unique in package, do I still need to specify the class name in order to use this static method ?

Thanks
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3070
    
  33

nirjari patel wrote: If I have created a class "testSpecifier1.java" with access specifier as protected , in package testClasses, I can access this class anywhere in same package.
I have to import package in a class to use content from that package. So if I create another class "testSpecifier2.java" in the same package testClasses, do I need to import this package in the beginning of the coding ? Or can I access content within same package without importing package ?


Please try to implement this by writing a simple code. So that you can get a first hand experience of how things work.

nirjari patel wrote: How doea this work with static methods ? As static methods dont need the class to be instantiated. If I dont need to import package to be imported for use in another class within same package, what if there are two static method by the same name in two different classes ? Do I need to specify class name before the static method name in order to specify what static methid I want to use ? If there is unique static method in a class which is unique in package, do I still need to specify the class name in order to use this static method ?


I think you are talking about Static imports- http://download.oracle.com/javase/1.5.0/docs/guide/language/static-import.html
Always better to avoid Static imports as it leads to confusion and difficult to maintain code.

Mohamed Sanaulla | My Blog
nirjari patel
Ranch Hand

Joined: Apr 23, 2009
Posts: 374
I am not talking about static imports.

I am just talking about protected class. If class access specifier is protected and I want to use this class members in another class in same package , do I need to import this package in the cclass or can I just use the methods without importing package ?

Thanks
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

nirjari patel wrote:I am not talking about static imports.

I am just talking about protected class. If class access specifier is protected and I want to use this class members in another class in same package , do I need to import this package in the cclass or can I just use the methods without importing package ?

Thanks


Good question. What happened when you tried it out? If you haven't yet, then I would recommend that you write up code which does what you want and try to both compile and run it.


Steve
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "protected" access specifier