Access Modifier: Only Subclass, not package wide?

Hello fellow programmers
I'm looking for an access modifier that allows access to a method or member only from a class and it's subclasses. So it must be weaker than private because subclasses have access and stronger than protected because I don't want it to be accessible package wide.
Is there such a modifier in Java?
Regards
Der Hinterwaeldler

There used to be in a very early version of the language but it was dropped for clarity. IIRC it was called "private protected." Now you have to settle for "protected."
This makes kind of sense since you have more control over the classes in your own package than over the subclasses that are not necessarily written by you ... If you can't trust other classes in the same package maybe you should put the class in a new package...

Similar Messages

  • Skype WiFi - an access tool only. Do not confuse ...

    What Skype WiFi does is provide a way to pay for access to the internet; rather than typing a credit card number in a public venue.
    You use your Skype credit to pay for the access fee, and only for minutes needed as opposed to having to purchase a day pass or block of time.  
    It is an access tool only. Not a wifi provider like Boingo or Cloud. 
    This is the main purpose of Skype WiFi. 
    Solved!
    Go to Solution.

    You open your browser and see the inital holding page of the hotspot provider.
    If Skype is an option given by the hotspot provider to pay for access at this point you can then follow the prompts and login.  It's an ACCESS tool only at this point -- NOT a contact tool for IM or video chat. That is only enabled once you have the WiFi connection, and Skype loaded to your PC.
    This service used to be called Skype Access. In hindsight it might have been better not to rename it!
    You pay for access by using your Skype credit - instead of your credit card. That's the only thing it offers!
    Once you login and pay using Skype credit, the hotspot is activated by the hotspot provider. You can then surf the web.
    Here's an example. INO_KOL has a hotspot. People who want access can pay him using either their credit card, or....if they prefer not to use a card (don't have one?), they can use Skype credit. So...... they open their browser and see INO_KOL's holding page. This has one of two things, a credit card payment option and a Skype user ID and password option which is only for them to enable the charging of their Skype credit.
    Which ever one they choose enables access to the web. 
    Hope this helps. 

  • Default/package/none access modifier

    Hi,
    I was hoping for some discussion on the default/package/none access modifier. It's always really bugged me that we have public, private, protected, and then "none", while it seems to me that it would be less confusing, and more consistent to use the keyword "package", or maybe even "default".
    Then, source code would look like
    public class MyClass{
        public int getValue() {}
        private void setValue() {}
        protected void someMethod() {}
        package int justForPackage() {}
    }I know this concept has come up before, but the books I've read which mention this topic haven't offered any actaul justification/explanation for why there isn't some keyword.
    Anyway, are there any insights as to why java is this way, and any reasons why java should or shouldn't be changed to include the package access modifier.

    A good example is within a tightly grouped package (usually should be this way) you may have some cooperative classes that access methods.
    // one .java file
    public class SomeHelper {
       private void method() {
         new ClassForUsers().accessHiddenLogic();
    // next .java file in same package
    public ClassForUsers {
        /* default-access */ void accessHiddenLogic() {
    }But, you may want to allow users to subclass your ClassForUsers, without giving them access to the hidden logic method directly:
    // another .java file in a different package
    public class UsersSubclass extends ClassForUsers {
        public void userMethod() {
            // can't do this
            accessHiddenLogic();
    }This could be for either business logic or security reasons. So, package level access can be very useful. However, I've seen that in practice it is avoided because it isn't obvious what is going on.

  • Access Modifiers, Package declaration

    I created the following two classes in the same folder as two source files:
    A.java
    package abc;
    class A{
    B.java
    package abc;
    class B extends A{
    When I tried to compile, A compiled successfully. But when compiling B, it gives an error Cannot find symbol for class A.... I think it should be visible as both class access modifiers are (default). Why do I get this error????
    By the way if package declarations are removed from both classes then they compile successfully........

    i tried a lot..... does classpath affects compilation??? can u correct dis???If we're going to make the effort to help you, you could show willing and make the effort to spell out all your words and generally make your sentences as easy to understand as possible.
    Yes, the classpath affects compilation as the link provided shows. YOU can correct this.
    >
    e:\one\>javac -classpath e:\one\cert B.java
    >
    The classpath points at directories (or JAR files) not Java source files. Read the link.

  • On imac 10.6.8 using current version of Aperture.  How can I access the Aperture Library  on my external hard drive that I use with time machine for backup?  I can only access the application but not the library..

    On imac 10.6.8 using current version of Aperture.  How can I access the Aperture Library  on my external hard drive that I use with time machine for backup?  I can only access the application but not the library..

    Go into Time Machine (the program not the bundle on the extrnal disk) and using Time Machine's browser go to the Folder where the library lives. You could look in the library bundle in Time Machine but that won't really tell you much,
    If you want to make sure it truely has backed up your library you will need to restore it and open the restored library with Aperture.
    If all this still has you confused you need to read up on Time Machine in order to get a feel for how it works, for what it is doing and for how to restore files from it.

  • When I run an Utilities check on the HD. I always get a prompt-SUID System/Library/CoreS has been modified and will not be repaired. how can i access this to be repaired. Most files are corrupted by messages that they are one thing but should be another

    When I  run a system utilities check and select HD. i always get a prompt the the SUID System/Library/CoreS has been modified and will not be repaired. How can I access this file so that I may repair it? Left unrepaired . There are a lot of files that do not have the correct code. They are one thing but should be another

    Hello there, toestothenose.
    It seems that you may not have gotten the entire message into your thread here, but the following Knowledge Base article offers a good resource on which messages from Disk Utility's Repair Disk Permissions can be safely ignored:
    Mac OS X: Disk Utility's Repair Disk Permissions messages that you can safely ignore
    http://support.apple.com/kb/ts1448
    Thanks for reaching out to Apple Support Communities.
    Cheers,
    Pedro.

  • How to setup the guest network just access internet only (not touch in internal server)

    I had setup the AirPort Extreme in basic and guest network, but observed the guest can access to our server currently, for the security issue, we can setup the guest network to access internet only? pleae advice and thanks

    By default, a properly configured Guest network on the AirPort Extreme only allows network clients to access the Internet. No access to the "main" network's resources should be available.
    This is assuming that the AirPort Extreme is the only or "main" router in your current network configuration.

  • HT4859 i want to access pictures from a backup only! not restore a device, how do i do this?

    I need to get acess to a backup, as in WHAT it backed up in terms of pictures. I do not want or need to restore a device, just access picturs.

    It is not possible to examine specific data stored in an iCloud backup, except by restoring it to your device.  If backing up with iTunes, it's possible to use 3rd party software to extract data from a backup, but not with iCloud backups.

  • Default class access modifier

    What is the default access modifier for a class? I can't seem to find it in the tutorials...
    Thanks
    Jim

    The default access is the same for top level classes that do not specify access explicitly as for other identifiers. Package.
    This single source file will create two class files in the same package. Only other classes in the package can see these top level package access classes.
    And, yes, this is a bad idea. In the case of some build tools, errors in a compile can cause the public class to compile, but the package class to fail. After that, the compiler will not be able to determine what source file to compile for the package level class. This is an error that confuses many developers. I do not recommend this practice. Put each top level class in its own source file.
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Access over elements of an package... :-)

    Hi,
    assume i create a package spec and body in a database using a database user id user1... now will others users be able to access or modify elements of the package spec (which are public), or does the user1 needs to grant access???

    With our own package our other programs can use any procedure or function in the package spec. When we grant EXECUTE privilege on a package to other users they have the access to call any method in the package spec. They do not have the right to modify the code in any way shape or form, unless they also have the CREATE ANY PROCEDURE system privilege (which only DBA accounts should have).
    Some times we need to restrict access to a subset of packaged methods. In that case we need to build an API, a new package consisting of a spec with just that subset of functions and a body that just wraps the calls to the origin package's functions. We only grant other users execute on the new package.
    Cheers, APC

  • Usage of default access modifier

    Some programmers don't use the default access modifier (package level). Is there a specific reason? If so, what is it? Or is it a good to use default access modifier?
    Thank you,
    Srikanth

    Some prefer to grant or limit access to an object by the interface they expose. In this case all methods are either public or private. Access is restricted based on the fact that only the appropriate code is given references of certain interface types and if code does not have the right interface, they can not access the method.
    Its a different style, but I use it myself quite a bit. This way I never am concerned over if it should be public,private, protected or default. The choice is simpler. But sometimes it can make you create interfaces for really simple things which I am not uptight enough to do...

  • Access Modifiers Effect on Static Method Hiding Question

    I am studying for my SCJP exam and have come across a question that I do not understand and have not yet found a satisfactory explanation.
    Given:
    package staticExtend;
    public class A{
         private String runNow(){
              return "High";
         static class B extends A{
              public String runNow(){
                   return "Low";
         public static void main(String args[]){
              A[] a=new B[]{new B(),new C()};
              for(A aa:a)
                   System.out.print(aa.runNow()+" ");
    class C extends A.B{
         public String runNow(){
              return "Out";
    }The output is "High High". The explanation in the sample exam from ExamLab was that because the runNow() method in A was private that only an explicit cast to the B class would invoke the runNow() method in B. I have verified that that is the case, but am not clear on how the runNow() method being declared static in B and how the private access modifier in A results in this behaviour.
    Any additional explanation would be greatly appreciated.
    Thanks in advance.
    -- Ryan

    Ryan_Chapin wrote:
    OK, so since runNow() in A is private the compiler determines that regardless of the available methods in any of it's sub classes that since we declared the original array reference as "A" that it will invoke the runNow() in A. It's also due to the fact that the invocation came from within A. You would have gotten a compile time error if you tried to place the code in the main method in another class.
    >
    My mistake about the second part that you mention. You are correct. runNow() in B is NOT static, but the class is static. I guess that was the red herring in this question I don't see how that is related. I actually think that the "red herring" was what I described above. The fact that the code was placed in A, and that private methods can't be overridden.
    and the fact that the class itself is static has nothing to do with the behaviour that is being illustrated. Is that correct?Correct

  • Private, protected Access Modifiers with a class

    Why cant we use private and protected access modifiers with a class?
    Thanks.

    Matiz wrote:
    >
    Public access allows you to extend a parent class in some other package. If you only want users to extend your class rather than instantiate it directly, make the class abstract and design for extension.Agreed. However, would the same argument be not true for the default access at the class level? No. Default access would only allow you to extend a parent class in the same package (as opposed to some other package).
    Now my confusion is why is a class allowed default access at the top level and not protected?Because protected for a top-level class makes no sense. The protected keyword provides member access to any other class in the same package and extending classes outside the package. A top-level class isn't a member of a class, by definition, so there's nothing that protected would do provide differently than public.
    So, the two access modifiers for a top-level class are public and default. Public allows access to the class outside the package, whereas default restricts access to the class within the package.
    ~

  • Access modifier for Constructors ???

    As constructors are not the so called Members of a class
    (Class's Member declarations include only 4 things : variables , methods, member classes and member interfaces)
    Why do we have access modifiers for constructors also ??
    I know that if a class A 's constructor is declared 'private' , then that class cannot be instantiated outside the class A. .That is, class A can be instantiated only inside class A and provide this newly created reference to the outside world through public getter method.
    I dont understand how the other access modifiers (protected and default ) apply to a constructor.
    Any help from ur side is greatly appreciated !!!!!

    Why do we have access modifiers for constructors also
    ??To prevent anyone from accessing them if they shouldn't.
    I know that if a class A 's constructor is declared
    'private' , then that class cannot be instantiated
    outside the class A. Or you use another c'tor. Or a static getInstance() method provided by A. You you simply shouldn't create an instance yourself anyway.
    That is, class A can be
    instantiated only inside class A and provide this
    newly created reference to the outside world through
    public getter method.Yepp.
    I dont understand how the other access modifiers
    (protected and default ) apply to a constructor. Same as at other places. No difference.

  • Protected and public access modifier - exact difference

    Hi everybody,
    Please help me to give an exact difference between protected access modifier and public
    Protected: Classes with in the same package as well as subclasses can access.
    Public : Classes outside the current class can access while declaring public.
    My doubt is that what is the practical difference between public and protected.
    I searched the net , but the information was not satisfactory to solve my confusion.
    Thanks & regards
    Parvathy

    Obviously doubt = lacks the ability to think for
    oneself.When one person raises a doubt, that does n't mean that he lacks the ability to think . He/She might have thought about it and if he didnt get a proper clarification then it will be posted in the forum.
    In such cases please dont discourage others who are ready to answer the subject.Without knowing the actual intention , i request you please dont reply like this

Maybe you are looking for

  • ZeroShock sleeve case for MacBook Pro is available...

    In case anyone is looking for one, the ZeroShock sleeve case fitted for MacBook Pro is available at: http://shinza.com/productinfo.php?productsid=57 Although the manufacturer is Japanese, the product is apparently in inventory and shipped from their

  • Urgent - Error in IE

    Hi Friends I'm developing Chat Application. I used to http tunneling to transfer the data from server to client and vice versa. I can send a request to server, but I couldn't get the reponse from server. I got exception as IOException when I used get

  • Macbook Air 2014 samsung ssd

    Hello everyone, I'm new to this forum and I just wanted to ask, because I'm wondering, if there are any MacBook Airs of 2014 with a Samsung SSD? I've read a lot of the slower Sandisk an Toshiba SSD's which showed up in many speed comparisions between

  • Use ot alternate BOM

    Hi We have alternate BOM of a GF material, How can i use boththe BOMS in MRP run, and If we run MRP 2 time for the same material Ist time i use BOM no 1 and in IInd run change the BOM and run the MRP what will be the impact on my PR`s Thanks

  • Change default schema

    HI All, We are in process of deploying "SAP Business Intelligence Adoption rapid-deployment solution" and we have a schema which is already created and didn't use the option "Allow multiple usage" during the time of creation, once we import modules p