Why does protected access also allow access from classes in same package

Having been asked the question and found myself unable to answer it, I wonder if anyone can explain the reasoning why protected access implies the default access as well?

Sure:
---------- class A ------
package pkg;
public class A
protected static int _a;
private int _i;
public A() { _i = _a++; }
public String toString() { return "instance "+_i; }
--------- class B ------
package pkg;
public class B
public B() { A._a = 27; }
--------- class C -----
public class C extends pkg.A
-------- class main ----
public class main
public static void main(String[] args)
pkg.B b1 = new pkg.B();
pkg.A a1 = new pkg.A();
pkg.B b2 = new pkg.B();
C c1 = new C();
System.out.println("a1 is "+a1);
System.out.println("c1 is "+c1);
The above classes are legal and compile and when
run, the output is:
a1 is instance 27
c1 is instance 27
(Please note, this is just an example of what is allowed and why I'm curious as to the advantages of this permitted behaviour, NOT what I would ever write!)

Similar Messages

  • Why does Garage Band want to access my contacts?

    Why does Garage Band want to access my contacts? (on my ipad)

    When does it ask you? When you are sharing a song to iTunes? Then it will use this information to auto-fill the artist data.
    Regards
    Léonie

  • Why does iMovie stop importing my tape from the camcorder even though it says it is still importing?

    Why does iMovie stop importing my tape from the camcorder even though it says it is still importing?

    It's difficult to be sure without doing some network packet sniffing, but if it were another app syncing, it would be an awful coincidence, since it seems to happen only while I'm in Reminders.app -- as soon as I click the home button and go back to the home screen, it stops; when I launch Reminders again, it starts again.
    Moreover, it happens when I am not in the house, which rules out iTunes syncing.
    Note that it's not the syncing spinner (i.e. two arrows chasing each other in a circle) -- it's the data access spinner (like the wait spinner in many apps and the apple.com search box).

  • Accessing a dll from classes in different packages

    Hello java community,
    I am new to Java and especially the jni so your help is greatly appreciated.
    I am having trouble accessing a Windows native dll from classes in different packages. I placed the .dll in my ClassPath. I am able to loadLibrary successfully from class X in my 'common' package. However, when I try to access the same .dll from another class Y in package 'notsocommon'. I get an unsatisfied link error. I changed the X.h file to include common in the function definition (eg. Java_common_X_functionName) and I did the same to the Y.h file (Java_notsocommon_Y_functionName). I am able to work with the dll from the X class but not the Y class. I don't know what I am doing wrong. I am very new to Java, so any help is appreciated.
    Thank you.

    I apologize to everyone for posting this. I figured out my mistake, it was in the dll and not in the java. Also using
    javah -jni notsocommon.Y
    creates the correct header file.

  • Why does my iphone send all text from only one of my contacts to my email?

    Why does my iphone send all text from only one of my contacts to my email? I'm curious to know if anyone else has had this issue with the Iphone 5s...

    imessage has a new setting that shows all emails associated with your apple id.  There are two sections, send and receive.  Since you are using the same apple id, Im sure if you adjust one of those settings to your mobile number instead of your appleid, it wont send double.
    You might also have to adjust your wifes settings too, so those emails dont overlap

  • Why does my Epson printer keep disappearing from my ipad

    Why does my air printer keep disappearing from my ipad

    reboot the router (and the printer). 
    If still happening, check your router settings.  Is it set so that the lease on the printer IP expires?
    The pad has to see the printer as active, and on the same wifi network as the pad.
    You might also want to see if there is a firmware update for the printer available.

  • Elements 11 - why does it not recognize RAW photos from Canon 70D?

    Elements 11 - why does it not recognize RAW photos from Canon 70D?

    Hi,
    The 70D requires Camera Raw 8.2 which is not compatible with Photoshop Elements 11.
    Your choices are
    1) Upgrade to Photoshop Elements 12
    2) Use the Canon DPP application to convert the CR2 files to TIF files and then import the TIF files into the organizer
    3) Use the free download of the Adobe DNG converter to convert the CR2 file to DNG files and then import the DNG files to the organizer.
    Note: if you are running on XP or Vista, you need version 8.3 of the converter - the latest (8.4) will not work.
    DNG  Converter 8.4
    Windows: http://www.adobe.com/support/downloads/detail.jsp?ftpID=5739
    MAC: http://www.adobe.com/support/downloads/detail.jsp?ftpID=5738
    DNG Converter 8.3
    http://www.adobe.com/support/downloads/detail.jsp?ftpID=5694
    Brian

  • Why does my IPhone 4 transfer  messages from Inbox to Trash right after downloading them?

    Why does my IPhone 4 transfer messages from the Inbox to Trash right after downloading them?

    if it was iMessage, you wouldn't be charged, because they don't send as sms.  I would contact your carrier, because this is a weird issue that is most likely happening from their end

  • HT204370 why does my video and sounds not play at the same time when watching movies

    why does my video and sounds not play at the same time when watching movies

    Welcome to the unity.
    Upon which device are you watching your movies and are you using a home theatre system for your audio.

  • [svn:fx-trunk] 5140: Removing [ExcludeClass] from classes outside the package.

    Revision: 5140
    Author: [email protected]
    Date: 2009-03-02 12:09:24 -0800 (Mon, 02 Mar 2009)
    Log Message:
    Removing [ExcludeClass] from classes outside the package.
    QE Notes: None.
    Doc Notes: None.
    tests: checkintests
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/flex4/src/mx/layout/HorizontalLayout.as
    flex/sdk/trunk/frameworks/projects/flex4/src/mx/layout/VerticalLayout.as

  • Why does MAX say %22The remote access list on this system is blank%22%3F

    I am building and deploying a real-time data acquisition/control system using LabVIEW RT (2012 SP1) and a PXI controller.  I've tested my software, and it runs fine, now that I've figured out how to build stand-alone executables for both the Host and RT Target systems.
    Due to a bug on the RT side (which I hope I've now fixed), I needed to "rebuild" my PXI Controller, reinstall LabVIEW RT and related software, and reconfigure all of the Tasks in MAX (version 5.5).  To save the Configuration (and simplify reconfiguring the Tasks and Channels), I tried to export the configuration using the Configuration Export Wizard in MAX.  However, there were some (minor?) inconsistencies in some of the devices (such as NI-488.2) between the Host and Remote systems that generated some errors.  I was able to correct this by asking MAX to do a Reset Configuration Data on the Host, and those problems went away.
    After exporting the NI Configuration Export File for my PXI, I decided to use MAX to Create Reports on both my Host and Remote PXI systems.  While reviewing the PXI's report, I noticed that the last entry in the report, called "Security", reads as follows:
    "The remote access list on this system is blank. This means that no remote system has access to this system."
    What does this mean?  Where is the "remote access list on this system", and how is it maintained?  Note that I haven't (yet) tried deploying my (formerly-working) Project to this (rebuilt) Controller, but I haven't made changes in LabVIEW, itself.
    If I look at the Properties of the RT Target in Project, the VI Server properties (still) show TCP/IP enabled (port 3363) with Machine Access given to "*" (all machines) and, similarly, all Exported VIs allowed access.
    Am I missing something?  Can I safely ignore the above Security report entry generated by MAX, or is there a hidden setting I need to find and change?
    Bob Schor
    Solved!
    Go to Solution.

    Norbert_B wrote:
    Bob,
    i am not sure about your situation, but it seems to me that it is connected to "Security" Settings. Please refer to the help in MAX, topic "Logging into your System".
    Norbert
    I agree, but I've never heard about "Security Settings" in MAX. When I first read your note, I went looking and couldn't find "Logging into your System".  I came back a day later, was going to write a "There is not such topic!" reply, but fortunately I looked again, and found it.  I suspect the reason I never ran into this was that my controllers were all using older BIOSes -- I'd just "rebuilt" this controller, including updating its BIOS, and ran into the Login prompt for the first time ...
    Thanks for pointing me in (what turns out to be) the right direction!
    BS

  • Keychain - why does every program want to access it?

    After I set-up MobileMe on my new Mac Mini, every program is now asking for access to the keychain? Whether I approve or deny does not seem to make a difference. Why is this happening now since installing MobileMe and why do the programs need to access it each time? Is there any way to disable this or grant approval so I don't get bombarded by window pop-ups each time a program is started?

    Can you give some examples of every program please. Applications such as email, IM etc use it to store passwords and usernames so that's normal. Are there abnormal programs requesting access?

  • Why does family sharing prevent one ID from having multiple families, it's not that uncommon for one person to have multiple families they're involved in.

    I was very disturbed to discover that Apple's family sharing only has the capacity for one family per ID. People nowadays are part of multiple families; whether through marriage or divorce, and those families don't necessarily want all their purchases shared with the other people. Why can't they just allow people to have multiple families, I understand there might be some complications with payment methods, but you could just let them choose which organizer they want to ask permission from, just like they would in a real family.

    I own the movies and I want them to stay in my iTunes library basically forever.
    But in both cases the file name no longer shows in the movie list, so I don't know how to re-download it from the Cloud.
    iTunes prefs > Store > Show iTunes in the Cloud purchases.
    This will show all your iTunes purchases in your library with a cloud icon down arrow. Click the icon to redownload or click on Play to stream without downloading.
    Also see this , -> Download past purchases
    and techncially, you don't "own" the movie, You simply have a license to use it.
    Yet the first thing iTunes does when you hit the delete key is tell you that it will remove the movie forever from all devices and the library.
    Actually, no it does not tell you that.
    FYI: You should keep copies of all yoru iTnue spurahses as the labels/movie studios/copyright owners can pull their product at anytime and it won't be available to redownload.
    Suggestions here -> http://www.apple.com/feedback/

  • Why does iphoto not import my photos from my camera?, why does iphoto not import my photos from my camera?

    why does iphoto not import my pictures?  is it because i used to have a pc and the camera is set up for that?  i photo can view the pictures but will not save them.

    What happens when you try?
    What brand of camera?
    Regards
    TD

  • Java file cannot access other class in same package???????

    I have written a bean as follows-------
    package CustTags;
    public class TomMovieBean
         private String movieName;
         private String movieDirector;
         public void setmovieName(String movieName)
              this.movieName = movieName;
         public String getmovieName()
              return this.movieName;
         public void setmovieDirector(String movieDirector)
              this.movieDirector = movieDirector;
         public String getmovieDirector()
              return this.movieDirector;
    Now i am writing a tag handler for my JSP custom tag as follows----------
    package CustTags;
    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;
    import java.util.*;
    public class Dynamic extends TagSupport
         private List movieList;
         public void setmovieList(List movieList)
              this.movieList = movieList;
         public int doStartTag() throws JspException
              Iterator iterator = movieList.iterator();
              TomMovieBean TMBObj = null;
              try
                   JspWriter out = pageContext.getOut();
                   while(iterator.hasNext())
                        TMBobj = (TomMovieBean)iterator.next();
                        String movieName = (String)TMBObj.getmovieName();
                        String movieDirector = (String)TMBObj.getmovieDirector();
                        out.println(movieName+"...."+movieDirector+"<br>");
              }catch(Exception ex)
                   throw new JspException("Error in doStartTag()");
              return SKIP_BODY;
    Now when i compile Dynamic.java it shows foll. errors
    Dynamic.java:19: cannot resolve symbol
    symbol : class TomMovieBean
    location: class CustTags.Dynamic
    TomMovieBean TMBObj = null;
    ^
    Dynamic.java:27: cannot resolve symbol
    symbol : variable TMBobj
    location: class CustTags.Dynamic
    TMBobj = (TomMovieBean)iterator.next();
    ^
    Dynamic.java:27: cannot resolve symbol
    symbol : class TomMovieBean
    location: class CustTags.Dynamic
    TMBobj = (TomMovieBean)iterator.next();
    ^
    3 errors
    I am unable to comprehend why it can't recognize TomMovieBean despite the fact that its a public class and in the same package as that of Dynamic.java

    Is your classpath set correctly? I.e. does it point to the directory containing the CustTags directory?
    BTW, by convention, package names are written in lower case.

Maybe you are looking for

  • 2 GB memory ample enough to handle iMovie tasks?

    Hello. I'm about to get a 2.33 GHz iMac with 2 GB memory. If any of discussion-board users have 2 GB memory, I'm curious if any of you find your machines locking up or not up to the task of handling iMovie projects in any way. Yea, yea: I know: More

  • Recording from a turnta

    I would like to record from a turntable. What hardware and software do I need?

  • Is there any function module for purchase order change

    Hi Experts, Is there any function module for purchase order change or i need to do new recording in me22n. Thanks, Senthil

  • Time Capsule - Windows 7 can't see disks

    Just purchased a Time Capsule 1 TB and installed it. I have 2 PC's connecting to it. One is a Windows Desktop running Windows 7 RC (final). It sees the Time Capsule, printer, and disks. That's cool. However, I have an HP laptop that is connecting to

  • Hd esterno letto solo dal WD TV

    Ho un problema da qualche giorno: ho un hd esterno da 500 gb in cui carico il materiale da dare in pasto al WD TV. Quando serve lo collego al pc per spostare nuovi file (in wifi l'operazione è troppo lenta) ed ora nè win8 (da errore codice 43 e dice