I'm confused about protected access - any insight ?

I'm trying to understand how the protected access modifier works. I have tried to compile some example code and I'm seeing behavior which appears to go against what the text I'm using claims should happen. To wit:
My understanding is that any subclass and any class in the same package has access to the protected member of a class. Default access (when no access modifier is used at all) allows access only to classes in the same package.
I have the following two classes:
//--------  Parent.java ---------------
package testpkg.p1;
public class Parent
    public int x = 7;
    protected int getXValue ()
        return x;
//--------- Child.java --------------
package testpkg.p2;
import testpkg.p1.Parent;
public class Child
    extends Parent
    public static void main (String[] args)
        Child child = new Child();
        System.out.println("Child X: " + child.getXValue() + "\n");
        System.out.println("Parent X: " + child.testParent());
    public int testParent ()
        Parent parent = new Parent();
        return parent.getXValue();
}I get the following compilation error:
$ javac -d ../lib Parent.java Child.java
Child.java:18: getXValue() has protected access in testpkg.p1.Parent
return parent.getXValue();
^
1 error
Now it seems to me that everything should compile fine since the Child class is a subclass of the Parent class, and as such should have access to the protected member method getXValue(). However this obviously isn't the case. It seems that the behavior is more like what is described for default access, i.e. no access by any class outside of the package, no matter if it is a subclass or not.
Can anyone enlighten me on this ? Am I missing something obvious ?
Thanks in advance for any feedback.
-James

You know that you don't have to use the "protected"
modifier.Yes you do.
In fact, when I learned Java, it was called
"package" scope, not protected. But the same
principle applies.No, the principles outlined above and in the Java Language Spec apply.
"protected" or "package" means that only classes
within the package itself can have access. You do not
actually have to place any modifier at all since this
is the default scope.No, protected adds the ability to access ex-package super class members from a child class instance. Try compiling the above example without specifying protected access.
Pete

Similar Messages

  • Can you password protect your mail so when you want to access any mail you must enter a password?

    Can you password protect your email so when you want to access any of your mail accounts you must enter a password?  In other words before I can see my mail I must enter a password.

    On Oct 10, 2007, Matthew Morgan answered this question (discussion is now archived). I wanted to inquire further to his comment:
        Matthew Morgan Los Angeles, CA
         Re: Password protect "Mail" 
         Oct 10, 2007 7:55 AM (in response to Chester Harlan)
         Cherster,
         You could go to Settings>General>Passcode Lock and set a password to secure all your      personal data. 
    Matthew - in which program are our suggesting going to Settings?
    Thaks.

  • Just bought a Nikon d750 and confused about adobe LR4 and PS6 support for the RAW files. I have DNG 8.7 but wondering if LR and PS will import direct soon Thanks for any advice

    Just bought a Nikon d750 and confused about adobe LR4 and PS6 support for the RAW files. I have DNG 8.7 but wondering if LR and PS will import direct soon Thanks for any advice

    Support for the Nikon D750 was introduced in the latest version of LR 5.7 and ACR 8.7 on Novemder 18th 2014.
    Further updates to LR 4 were stopped when LR 5 was released on June 9th 2013. No further updates for bug fixes and new camera support.
    Nada, LR 4 will never support Nikon D750. The Nikon D750 was introduced into the market in September 2014 some 15 months after further development of LR 4 was discontinued.
    You can use the Adobe DNG program (free download for the package) to convert the Nef (raw) files from your Nikon D750 to the Adobe DNG format which will permit you to import those into LR 4. This is the crutch provided by Adobe to allow for the processing of raw files with outdated versions of LR and ACR.
    You can also update the ACR plugin for PS CS6 to version 8.7 which can also work with the raw files from the D750. For direct support in Lightroom you will need to upgrade (paid) to version 5.7.

  • I am trying to help a friend who`s imac is giving her trouble. when the user logon is typed the machine begins to load, then in about a minute, kicks back out into the logon screen. ANY insight to her problem will be greatly appreicated?

    I am trying to help a friend who`s imac is giving her trouble. when the user logon is typed the machine begins to load, then in about a minute, kicks back out into the logon screen. ANY insight to her problem will be greatly appreicated?

    Start up in Safe Mode.
    http://support.apple.com/kb/PH11212?viewlocale=en_US
    Repair Disk
    Steps 2 through 8
    http://support.apple.com/kb/PH5836
    http://support.apple.com/kb/ts1417

  • I just updated Creative Cloud to 1.9.1.474, and my entire CC folder just disappeared. And I can't access any of my 18GB of files on the web. What the hell is going on?

    CC says it's re-syncing all 18 GB of my files back to my HDD. I'm on crappy wifi in southern Peru, and I can't access any of my work files for (CC estimates) 22 hours. I'm basically out of business for a day or more. How the hell can Adobe allow this to happen?

    With the recent update of the Creative Cloud Desktop app (1.9.1.474) we unfortunately introduced a bug which causes the creation of a new Creative Cloud Files folder, and re-sync of all content. This will only occur the first time the sync application runs after the update. This has caused understandable pain and confusion, for which we truly apologise.
    The Creative Cloud Files app contains logic that supports the use of multiple Adobe IDs. This allows you to sign out of one ID and in to another, but keeps your Creative Cloud content separate. When you sign out and change IDs, the app moves the previous Creative Cloud Files folder and it's contents and appends it with the previously signed in ID (User@AdobeID). It then creates a new main folder and starts to sync content of the new ID.
    The bug which I mentioned previously occurs, as the app believes an ID switch has taken place and as such, moves the current Creative Cloud Files folder and tries to append the previously signed in ID. As no switch has actually taken place it manifests as (Unknown).  The app then creates a new main folder at syncs down the data.
    Essentially what you end up with is a Creative Cloud Files folder with your newly sync'd data and a Creative Cloud Files (Unknown) folder that contains duplicate data.
    This occurs once, after the last update completes.
    The fix is to simply delete the Creative Cloud Files (Unknown) folder.
    I would advise that you ensure you have no pending edits that you may have made offline and that you check the contents of the new, main Creative Cloud Files folder contains everything you expect it to.  If not, check the contents of the Creative Cloud Files (Unknown) folder.
    If there is still a discrepancy with your data, you can check on creative.adobe.com to confirm your data is there.
    If you have any further problems or questions about this particular issue please email [email protected]

  • I'm confused about the apple ID transition from my aol screen name. Does it continue to use my aol email as my apple ID, converting it somehow or do I need to provide a new email address or just create a new username for the apple ID?

    I'm confused about the transition to an apple ID that doesn't use my aol email to sign in. The instructions are vague and ambiguous. Any help would be appreciated.

    OK, so if your current Apple ID using your AOL Username (like johndoe), then you need to log onto Manage your Apple ID and EDIT that AOL Username to a valid email address: Apple - My Apple ID
    If you have an AOL email address (like [email protected]), and you are not using that as another Apple ID, you can change the AOL Username Apple ID to that. Otherwise, you can change it to any valid email address (which you will have to verify when you change to it).
    Hope that clears it up. Post back if it doesn't!
    Cheers,
    GB

  • Confused about transition from MobileMe

    Up until now I actually have been happy with MobileMe.  But I wanted to transition to iCloud since MobileMe will shut down at the end of June.
    So today, I started the transition to iCloud.  However, I am confused about how to set up all the devices we used to use on MobileMe.  Before our family shared five computers, three iPhones, one iPod Touch and 2 iPads.  Under MobileMe, we were able to all share the calendars and contacts.  Now I have no idea how to have multiple devices share calendars and contacts.  Each person in my family has their own separate Apple ID.  Is there a way that multiple Apple ID's can share on iCloud account?  If so, how do we set that up?  I have no idea how to get one machine to see the general iCloud account.
    Any help or insight would be greatly appreciated.
    Thanks in advance.

    Actually, that was changed in the iOS 5.1.1 update. You can now stop the phone from defaulting to CDMA by going into Settings>General>Roaming>International CDMA and making sure it's set to "off". While it doesn't sound as if there's any harm in setting Data Roaming to off, I don't think it matters in this circumstance.

  • I'm new and confused about "connection" things

    I'm new to BlackBerry--I have an 8320 Curve, I'm a small business owner and I'm not connected to a BES. I use the BB Desktop Manager to synchronize with Outlook and to back up my BB and I've done pretty well on most things, but I still have a few things I'm confused about. In this forum, I'll ask my "confusion questions" concerning data options.
    I have a "pay as you go" data plan with AT&T, my provider, because there is virtually no cell reception at my home where I also work. (I'm not using my BB for email since I'm in front of my computer most of the time). I have a home network set up and I've incorporated a router that supports wireless. I've connected a netbook to the wireless network and used it to surf the Internet, so, I know my wireless connection works. I've also managed to create a wireless connection on my BB to this network and on the Home screen, it will display my wireless network's name when I'm here at home, so, I know the device is connected to my network.
    BUT, I don't think I'm actually using my home wireless network...I tried the other day by browsing the Internet and then AT&T told me I incurred data charges--which I thought I shouldn't have if I wasn't using their network. Either I'm wrong about assuming they won't charge me if I use my network or I have something set up incorrectly on my BB...can anyone provide some guidance?
    Next, I don't truly understand what BIS is...I searched through the KB and couldn't find anything that actually defines BIS...could somebody please explain what BIS is?
    Finally, can somebody please explain the difference between "mobile network" and "wi-fi"? It seems, if I turn off "mobile network" I have no connection at all, including wi-fi. Is that the way things should be? But, I can turn off wi-fi and still get a connection (if I go outside as far from my house as possible and face south <g>).
    Thanks...and now I'm off to the BB Desktop Manager forum to ask a few questions there!
    Solved!
    Go to Solution.

    Hi and Welcome to the forums!
    I can help you with one or two of your questions:
    ejm1 wrote:
    Next, I don't truly understand what BIS is...I searched through the KB and couldn't find anything that actually defines BIS...could somebody please explain what BIS is?
    BIS is Blackberry Internet Service...a service, hosted by your carrier, that provides a conduit between internet facing email systems (e.g., Yahoo, GMail, etc.) and your BB. Inside of BIS, you create conduits for each of your email providers that you desire to receive OTA email for on your BB. BIS will check your provider on a periodic basis (documented to be every 15 minutes) and only when there is something that needs to come to your BB does it generate any traffic over the carrier network with your BB. BIS is an add-service, only available to those who, from their carrier, contract for The Blackberry Data Plan (as it is usually called) -- a generic data plan is not usually adequate to have access to BIS.
    ejm1 wrote:
    Finally, can somebody please explain the difference between "mobile network" and "wi-fi"? It seems, if I turn off "mobile network" I have no connection at all, including wi-fi. Is that the way things should be? But, I can turn off wi-fi and still get a connection (if I go outside as far from my house as possible and face south <g>).
    Mobile Network is your carriers network...data and/or voice services provided OTA for your BB. WiFi is wireless networking (802.11a/b/g/n) through your home WAP, hotspots, etc. I don't know if turning off Mobile Networ should or should not affect your ability to continue to use WiFi...I would think they are separate, but I don't have a BB model with WiFi.
    I know nothing about the pay-as-you-go programs, but from all you describe, it seems that you may well be using your carrier network at times. You will need to find out (and there are others here who know) how to shut off your carrier network yet leave WiFi running so that you don't incurr the costs of surfing via the carrier network.
    Hope that helps a little!
    Occam's Razor nearly always applies when troubleshooting technology issues!
    If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
    Join our BBM Channels
    BSCF General Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Confused about accounts

    We are trying to set up security using account but i'm a bit confused about it.
    We have for example a structure like this:
    * Company
    ***** Section 1
    ********* subsection A
    ********* subsection B
    ***** Section 2
    ********** subsection A
    ********** subsection B
    1) When i define a path like company/Section1/subsection A
    does the user also have right to company, Section 1 or does he only has right to subsection A of section 1?
    1.B) If user has right to company, section 1, how can i give a user only rights to section1/subsection A?
    1.C) if user doesn't have right to company, section 1, how do i give a user right to all folders above?
    2) can i define "subsection A" so user has right to section1/subsection A and section2/subsection or does a path always have to start from the root?

    Account permission are inclusive.... so if you give some user read permission on Company account then he will get read permissionon Section 1 ,subsection A ,subsection B, Section 2 , subsection A ,subsection B.
    If you want to give a user read to one of the subsection then dont give him read permission on any of the parent of the subsection.e.g. you will need to give him access rights on "Company/Section1/subsectionA"
    1
    A)only has right to subsection A of section 1
    B) only rights to section1/subsection A, remove his other rights and give him rights to
    "Company/Section1/subsectionA".
    1.C) if user doesn't have right to company, section 1, how do i give a user right to all folders above?
    can you please elabrate on this question.....
    2) can i define "subsection A" so user has right to section1/subsection A and section2/subsection or does a path always have to start from the root?
    I think it will have to start from the root.
    regards,
    sapan

  • Confused about different calendars

    I have a Macbook Pro, an iPhone 5, and an original iPad.
    I am confused about the purpose of the different Calendars: Home, Calendar, iCloud, and Calendar([email protected]).
    Also listings on my iPad "Show Calendars" : From My Mac, cal.me.com, and [email protected]
    I am retired and have no work commitments so I just need one calendar that I can access and put events in from all 3 devices and can see them on all 3 devices.
    I find that if I put events in from my Macbook, they show up on both ioS devices, but if I put an event in on my iPad, it does not show up on my Macbook regardless on which Calendar I enter it on.
    Is there somewhere I can find in simple terms which calendar I can use on all 3 devices and delete the others?
    Thank you.

    Hi,
    Macworld has a great article on multiple apple ID's and imatch.   Here's the link: hope it helps.
    http://www.macworld.com/article/163013/2011/10/all_about_icloud_common_signup_sc enarios.html
    It runs through a whole bunch of multiple ID's & set-up scenarios.
    Cheers,

  • Default/protected access question

    Why does this work:
    The class below extends TreePath but is in a foreign package to TreePath. The call at *1* is to a constructor in TreePath that has "default" access. Shouldn't this fail to compile since the "default" modifier only allows classes in the same package access? The call at *2* works as I would expect since the TreePath constructor being called there has "protected" access.
    Thanks,
          * Subclass of treepath with needed public constructors.    
         private class ExtendedTreePath extends TreePath {
              public ExtendedTreePath(Object singlePath) {
                   super(singlePath);                                        // *1*
              public ExtendedTreePath(TreePath parent, Object lastElement) {
                   super(parent, lastElement);                               // *2*
         }

    Hmm... That is odd. I get a slightly different, but no more helpful, compiler message. I know that an object has to implement Cloneable in order for the clone to succeed, but that's just a tag interface that should lead to a runtime exception.
    I think a slight adjustment in thinking about "protected" explains it:
    "Protected means it can be called by classes in the same package, and by subclasses, and this class (like every class) is a subclass of object, so why can't it be called?"
    That's what I thought. What I would suspect is the case, though, has to do with clarifying the "and by subclasses" piece of that rather imprecises wording of the rule.public class MyClass extends Object {
        public void meth() {
            Object obj1 = new Object();
            Object obj2 = obj2.clone(); // or, I imagine, any protected method would fail here
            MyClass mine = new MyClass();
            mine.meth2(); // this should work, It think
            super.clone(); // this should work
        protected void meth2() {
    } I don't really know how to word this very well, but it seems that we can only call protected methods on super, or, I would guess, on other members of our class. We can call Object's clone (or other protected) method if we're call it on super, but not on an arbtirary object.
    I don't know if that's correct, but play around with it, or re-read the relevant parts of the JLS and see if it jives.

  • 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.
    ~

  • Confused about color vs. b/w photos for printing...and more

    I reading confusing things about exporting a PDF for printing with both color and black and white images used in the same document.
    If I export to PDF and do a soft-proof and it looks okay, is that sufficient? If so, what's confusing about that, since this is my first print project, which Simulation Profile do I use? Is there a chart somewhere that compares U.S. Web Coated (SWOP) v2 to let's say 80 lb Gloss book with Aqueous coating (C2S)?
    I don't know what any of this means. So, is there a good article on this site, elsewhere, or an online printer who can help a rookie like me ensure I end up with a decent product?
    UPrinting.com advertises a "Free Project Review" that includes the following:
    Our team will run your file through a 30-point inspection, covering technical issues including:
    Artwork dimensions
    Bleed setup
    Low resolution images
    Elements that are not within the safe zone
    Image clipping
    Font sizes
    Un-embedded fonts
    Folding setup
    Page scaling
    Line weights
    Proper text spacing (compressed/expanded)
    Narrow borders that are at risk of being cut
    Compliance with USPS Mailing Guidelines
    Bindery setup for multi-page artwork
    What should I do? Is this trustworthy as long as I get a contract proof? Is there a "Go To" online printer that everyone loves (not sure you can recommend that here) or should I seek out a local printer?
    I'm using CS4 and have a file that's (maybe) ready to go but am looking at a learning curve of days if not weeks if I have to figure it all out myself.
    Thanks everyone.
    Paul

    InDesign puts grayscale and B&W (bitmap mode) art on the Black plate, where it belongs, so if you soft proof using the CMYK profile for your expected output conditions your preview will be accurate for the grayscale and B&W images as they will appear in print. presuming your monitor is calibrated and profiled so that you can trust what you see.
    Aqueous coating is applied AFTER the printing to protect, and possible enhance the glossiness of, the page (but not all coatings are glossy). This is not the same thing as printing on coated paper, which has a glossy surface and high ink holdout (and improves detail reproduction and usually will geive better color). You should be using whatever profile the printer has specified.

  • My iphone5 screen flashes when trying to make a call.  I can't access any of screen features.

    My screen flashes when trying to make an outgoing call.  I am unable to access any of the screen features such as keyboard etc.

    Could be a problem with the proximity sensor. Are you using a case around your phone or a protective film attached to the screen? If yes, remove them, to make sure that the sensor is not covered.
    Also try to reset the phone by holding the sleep and home button for about 10sec, until the Apple logo comes back again. You will not lose data by resetting.

  • Confused About Catch Up

    Hi everyone, So I have  just had Sky installed and I am a little confused about some aspects of it and I hope someone can give me some advice. The catch up service: Is it normal for there to be very little actual content in the catch up section?When I was looking at the various options on offer, one of the things that I really liked the look of was the '30 day catch up service'.
    I (possibly incorrectly) assumed this would mean I could access the vast majority (if not all) of the programmes shown on Sky for the last 30 days. When I look in the catch up section, there is very little choice there.For example - in the sky channels section, sorted by day - for last Saturday there are only four shows. Is this a fault or is catch up a whole lot less than it promises to be? I have the family package by the way and I realise that I can only access channels and catch up that I am subscribed to but it seems very poor to me that the 'catch up' service amounts to just a handful of shows, most of which I am not interested in. Strangely, when I manually search in the search box for a specific show, I get on-demand results that I cannot find anywhere else in the EPG. Is there more on demand content there but only if you know exactly what you want to search for and use the search box? It seems odd to me that I have to know what I want to watch and search for it manually, I cannot just browse a list of available shows. Pushed on demand: So the way I understand it is this, my 500GB hard drive has 250GB partitioned off for the sky box to download content to overnight. Where do I access this content?I can't find any of it.I have read the manual and it says I will see a little play icon on content that is available to watch which, I assume, refers to content automatically downloaded by the box. I have seen this icon on one show. That's it. Is 250GB of space being used for nothing?Can I get that space to use for my own downloads and recordings?I know there is a setting to turn off 'pushed on demand' but does this free up the space reserved? Sorry if this has been covered elsewhere or if I am asking stupid questions and thanks in advance for any replies. Broddr.

    Thanks for the reply Annie.
    I did as you suggested and still get no more.
    Pressing the green button and selecting channels just splits the five shows up into their specific channel.
    I have five shows total.
    I select Nat Geo channel and it shows the three of those five shows that are on Nat Geo.
    I select Nat Geo Wild and it shows the remaining two of those five shows that are on the Wild channel.
    I have been through all the system settings and every page on the box OS again and again and I am coming to the conclusion that I do not have a problem as such, rather the service is simply pants!
    Apparently my 'catch up' service for Nat Geo for the last four days consists of one programme!
    I suppose for an 'extra' service I can't really complain, but the touted '30 day catch up service' was one of the main reasons I signed up.
    I would argue they should not really call it 'catch up'.
    'Selected highlights' is probably more accurate.
    "Catch up on the best of sky over the last thirty days - as long as, for example, what you want to catch up on SyFy is Dark Matter and Defiance 'cos that's all there is."

Maybe you are looking for

  • Iphoto 6 Thumbnail Viewing/Indexing Problem

    i recently upgraded to iphoto 6.0.5 and my photos get out of order within the albums when i use the blue scroll bar to go up and down through my different albums. Pictures from different albums appear out of order. when i stop the scroll bar and/or c

  • What version of Adobe Reader Extension  ?

    hi, I am running Adobe Reader Extension v7.0 to certify form. We have a couple of issues of form which behave differently when forms are openning in browser and form operates on Windows. Basically, the checkbox is not checked etc.. Does anybody know

  • Java.exe problem

    Hi, Would anybody please help me with this problem. I tried to execute java.exe with the command: java -Djava.library.path=E:\Program Files\Testing TestApp, it threw exception could not find the the path since there is a blank space between Program F

  • Keep Pool question

    If I specify db_keep_pool_size as 200 M and I am presently keeping 150 M of tables and indexes in keep pool. What happens when the size of these segments goes beyond 200 M? Does the query throw an error? Thank You

  • How do I merge Aperture libraries?

    On rather poor advice, I started splitting my Aperture library by year -- I did this by setting up a smart album for each year and clicking "Export > Smart Album as New Library..." I now want to merge them back together but am not sure how. I am also