Accessing inner protected class with .new

My weak understanding is that inner classes are no different in terms of access modification as other class members, thus I was expecting the following to compile:
package A;
public class ClassA {
    protected void protectedMethod() {}
    protected class ProtectedInnerClass {}
}is being used over here in package B
package B;
import A.*;
public class ClassB extends ClassA {
public static void main(String[] args) {
ClassB b = new ClassB();
b.protectedMethod(); // works fine. I am inheriting ClassA and calling the protected method.
ClassB.ProtectedInnerClass c = b.new ProtectedInnerClass(); // compiler error: ProtectedInnerClass is protected
}Why can I not access the protected inner class when ClassB is inheriting it as is the case with the protected method?
thanks in advance!

So classes that inherit other classes with protected inner classes will not be able to instantiate these inner classes regardless of the inheritance relationship.No, that's not true. Example:
package A;
public class ClassA {
     protected void protectedMethod() {
     protected class ProtectedInnerClass { // class is protected
          public ProtectedInnerClass() { } // <-- nota bene
package B;
import A.ClassA;
public class ClassB extends ClassA {
     public static void main(String[] args) {
          ClassB b = new ClassB();
          b.protectedMethod(); // works fine.
          ClassB.ProtectedInnerClass c = b.new ProtectedInnerClass(); // works fine, too.
}It's section 6.6.2.2 that describes this behavior, as I quoted above. The last bullet point of that section reads (to repeat): "A protected constructor can be accessed by a class instance creation expression (that does not declare an anonymous class) only from within the package in which it is defined."
~

Similar Messages

  • [svn:osmf:] 13083: Updated MASTAdapter class with new trait names and events.

    Revision: 13083
    Revision: 13083
    Author:   [email protected]
    Date:     2009-12-17 16:10:05 -0800 (Thu, 17 Dec 2009)
    Log Message:
    Updated MASTAdapter class with new trait names and events.
    Modified Paths:
        osmf/trunk/plugins/MASTPlugin/org/osmf/mast/adapter/MASTAdapter.as
        osmf/trunk/plugins/MASTPluginIntegrationTest/src/org/osmf/test/mast/TestMASTPluginInfo.as
        osmf/trunk/plugins/MASTPluginIntegrationTest/src/org/osmf/test/mast/adapter/TestMASTAdapt er.as

    Silviu!
    I'm really sorry, but as all the office is trying to fix the problem, someone replaced the url content with the stuff that was pointing to the local machine.
    I've fix it, and the video player is available here again: http://pp.player.webtv.flumotion.com/params/apiKey/5PzLR2ULL3z2rumJ/videoId/60
    If there are other references to the localhost, please do not bother with them, as they do not affect player functionality.
    The stream that it uses is an RTMPE, so i'm afraid it will only works with this player. Anyway, the stream url is as follows: rtmpe://87.248.205.81/a4349/e2/veo7/ondemandrtmpe/mp4/med/first-person-mario-4d8741aa.mp4
    I really appreciate your help!
    Thank you!

  • Enhanced SAP class with new methods - Not showing these from standard task

    Dear Gurus,
    I have enhanced SAP standard class with new methods. After I have activated my new methods and would like to create a workflow task using these new methods. when I create a task and input object category as "ABAP Class" and object type is SAP enhanced class. When I try to drop down for methods SAP is not showing my new methods. I do not know why. Am I missing any? Any help would be appreciated.
    Note: Remember I am trying to use SAP ABAP class custom methods.
    Thanks,
    GSM

    Hi,
    Your thread has had no response since it's creation over
    2 weeks ago, therefore, I recommend that you either:
    - Rephrase the question.
    - Provide additional Information to prompt a response.
    - Close the thread if the answer is already known.
    Thank you for your compliance in this regard.
    Kind regards,
    Siobhan

  • Extend standar class with new button(method)

    Hi,
    I want to create new button in standard class /SAPSRM/IF_PDO_AO_BP_BASE.
    Does anyone know how to extend the class with a new button?
    Very thanks.

    I NEED TO CREATE NEW BUTTON IN THIS CLASS.
    THE BUTTON MUST SHOW A POP-UP WHEN PARTNET HAVE DOCUMENT´S IN SYSTEM.
    CAN YOU HELP ME?

  • Set up DynDNS access through existing network with new Airport Extreme

    Hey everyone!
    I just can't seem to figure out what I am doing wrong here...
    I am working with an office network which was initially set up with a Linksys router and a separate Linksys hub connecting two Macs and a network printer in one particular room. We added several new iMacs and for ease of connectivity, decided to add a new Airport Extreme base as one of the new iMacs is acting as a server for a database the other new wireless iMacs connect to. Also, all the machines need access to the connected network printers connected in various parts of the office.
    What we have now is the original Linksys router -> Linksys hub -> Airport Extreme. Everything seems to be working fine this way but I do believe that both the Linksys router AND the Airport Extreme are distributing IP addresses, which I'm thinking, could be the problem. I set up a DnyDNS account just fine, assigned port # 8080 on the server iMac and also opened port 8080 on both the Linksys and Airport Extreme. I still cannot get through to the server via DynDNS however.
    I am wondering if I should turn off IP distribution on the Airport Extreme and let the Linksys router handle all that? The software that the other wireless iMacs run to access the database on the server depends on the server IP address too, so will this need to be changed if the Linksys is handling IP addressing? How does the hub affect any of this... does it change or interfere with the addressing in any way?
    Thank in advance for any ideas or suggestions!

    maxyourmacs, Welcome to the discussion area!
    I am wondering if I should turn off IP distribution on the Airport Extreme and let the Linksys router handle all that?
    Yes
    The software that the other wireless iMacs run to access the database on the server depends on the server IP address too, so will this need to be changed if the Linksys is handling IP addressing?
    Probably
    How does the hub affect any of this... does it change or interfere with the addressing in any way?
    It has no affect.

  • No longer have access of an app with new iPhone 4s..

    I downloaded the app PRT and paid for the 5 k module but I recently changed / upgraded  iPhone to the 4s and now I do not have access to the module .
    I would like to avoid paying the $3.99 plus tax again how can I get this rectified?
    I also do not have access with this new phone one of my songs purchased would this be the same problem

    You'll want to contact Apple Support by phone to have them walk you through the process of getting this older account cleaned up and your issue resolved.
    http://www.apple.com/contact/
    B-rock

  • Problem accessing iTunes for apps with new iPad

    New iPad connects to and works fine with home wifi except when trying to download apps. Then I get message that I cannot connect to iTunes. Don't have this problem when using public wifi.

    https://discussions.apple.com/message/18247628#18247628

  • Can't access all internet pages with new wifi

    I just moved and my apartment complex has free Wifi. I can access most web pages but can't open for example fox.com, abc.com. A message says I am not connected to internet. I have to login to the wifi service and I am recognized. I don't know if it is my computer or wifi. Thanks

    Im willing to bet its the wifi. Reason being is I have had a similar experience with my old wifi router. I would get a dropped connection and i thought it was my macbook and PC. Turned out it was my router and once i upgraded to a Airport Extreme, everything has been fine and i have not had a single dropped connection. If its in an apartment complex, Im willing to guess they have a normal router from wherever its transmitting from and the router cannot handle the load. Perhaps someone is also trying to access the router not knowing passwords and this causes the router to lag and kick people off. Try bringing your computer to a friends house with wifi and try loading the pages there.
    Hope this was a little useful.

  • Protected class

    hi ppl,
              Iam new to this oops concept..i learnt that to access the contents of a protected class either we have call by subclass and another is with in itself.so how can we call a protected class with in class itself..pls do alter this code to call within itself
    class snap definition.
    protected section.
    methods: m1.
    data: d type char20 value 'PROTECTED'.
    endclass.
    class snap implementation.
    method: m1.
    write:/ d.
    endmethod.
    endclass.
    start-of-selection.
    data obj type ref to snap.
    create object obj.
    call method->m1.
    end-of-selection.

    Hi Priyank,
    Marcin's correct but there was a small typo in his post:
      me->me1( ).
    Is supposed to be:
    me->m1( ).
    as m1 is the name of the protected method. In case you're wondering, "me" is a self reference to the instance. It is not necessary, e.g. you could write just
    m1( ).
    but including the self reference is considered good practice because it increases the understandability of the code.
    Best regards, Erik

  • ECATT: How to access a protected method of a class with eCATT?

    Hi,
    These is a class with a protected method. now i am willing to automate the scenario with eCATT. Since the method is Protected i am unable to use createobj and use callmethod. Could anyone suggest me a work around for this ?
    Regards
    Amit
    Edited by: Amit Kumar on Jan 10, 2012 9:53 AM

    Hello Anil,
    You can write ABAP Code to do that inside eCATT Command.
    ABAP.
    ENDABAP.
    Limitation of doing that is you can only use local variable inside ABAP.... ENDABAP. bracket.
    Regards,
    Bhavesh

  • Outer Class Accessing Inner Classes Variables

    Hi Everyone,
    Should an outer class directly access the private member variables of its inner class? Or should it get their values by calling an appropriate 'getXXX()' method?
    Just wondering.
    Thx.

    If the outer class trys to access the variable that is declared in the inner class with in a class and outside the method, then it can access in the following example
    class outer
         private int x=10;
         class inner
              int y=20;
         public void getOutput()
              inner in=new inner();
              System.out.println("The value of y is" +in.y);
         public static void main(String args[])
              outer out=new outer();
              out.getOutput();
    };

  • EJBs accessing protected classes from java classloader

    Hello,
    We are facing a problem with classes isolation. I read from this newsgroup that
    to access a package level class from the base classloader from a bean, the supporting
    classes has to be from the same classloader as the bean. Well I think the only
    way we could do that is to have the *Bean.class in the base classloader, which
    is not what's recommended or move the support classes into the bean's classloader,
    which we cannot do.
    The purpose of this mail is to ask: is it a bug from weblogic server? Will it
    be fixed one day? If not, does it mean that it is impossible to isolate classes
    for local access from public classes?
    Thank you, Khiet.

    Thank you for your reply.
    Hope that one day we will not be obliged to have anything in the main classpath.
    :) Khiet.
    Rob Woollen <[email protected]> wrote:
    Tran T. Khiet wrote:
    Hello,
    We are facing a problem with classes isolation. I read from this newsgroupthat
    to access a package level class from the base classloader from a bean,the supporting
    classes has to be from the same classloader as the bean. Well I thinkthe only
    way we could do that is to have the *Bean.class in the base classloader,which
    is not what's recommended or move the support classes into the bean'sclassloader,
    which we cannot do.All correct.
    The purpose of this mail is to ask: is it a bug from weblogic server?No, it's how java classloaders work.
    Will it
    be fixed one day? If not, does it mean that it is impossible to isolateclasses
    for local access from public classes?You can expect that future versions of WLS will allow the user more
    control over classloaders, but for now you'll need public or protected
    access to cross classloaders.
    -- Rob
    Thank you, Khiet.

  • OOABAP-How to access the protected methos from a class

    How to access the protected methos from a class..There is a built in class..For tht class i have created a object..
    Built in class name : CL_GUI_TEXTEDIT
    method : LIMIT_TEXT.
    How to access this..help me with code

    hi,
    If inheritance is used properly, it provides a significantly better structure, as common components only
    need to be stored once centrally (in the superclass) and are then automatically available to subclasses.
    Subclasses also profit immediately from changes (although the changes can also render them invalid!).
    Inheritance provides very strong links between the superclass and the subclass. The subclass must
    possess detailed knowledge of the implementation of the superclass, particularly for redefinition, but also in
    order to use inherited components.
    Even if, technically, the superclass does not know its subclasses, the
    subclass often makes additional requirements of the superclass, for example, because a subclass needs
    certain protected components or because implementation details in the superclass need to be changed in
    the subclass in order to redefine methods.
    The basic reason is that the developer of a (super)class cannot
    normally predict all the requirements that subclasses will later need to make of the superclass.
    Inheritance provides an extension of the visibility concept: there are protected components. The visibility of
    these components lies between that of the public components (visible to all users, all subclasses, and the class itself), and private (visible only to the class itself). Protected components are visible to and can be used by all subclasses and the class itself.
    Subclasses cannot access the private components  particularly attributes) of the superclass. Private
    components are genuinely private. This is particularly important if a (super)class needs to make local
    enhancements to handle errors: it can use private components to do this without knowing or invalidating
    subclasses.
    Create your class inse24 and inherit this CL_GUI_TEXTEDIT
    class in yours. You can then access the protected methods.
    Hope this is helpful, <REMOVED BY MODERATOR>
    Edited by: Runal Singh on Feb 8, 2008 1:08 PM
    Edited by: Alvaro Tejada Galindo on Feb 19, 2008 2:19 PM

  • How can I use the old Apple TV with new iTunes?  It tells me to input a code in iTunes but iTunes no longer has a spot to input this code to allow sync.  I can access the iTunes Store fine, just none of my Library

    How can I use the old Apple TV with new iTunes?  It tells me to input a code in iTunes but iTunes no longer has a spot to input this code to allow sync.  I can access the iTunes Store fine, just none of my Library

    read this
    https://discussions.apple.com/message/20429789#20429789

  • 2504 with new-architecture enabled breaks MAC auth for guest access

    Hello,
    We have (2) 2504 WLC running version 7.6.120. WLC1 is the local controller and WLC2 is an achor controller for guest-access. We need to incorporate a 3850 for use with the WLC2 anchor. The guest access is currently working with Mac-Auth and Mac-Auth-Fail to Web-Auth.
    When converged access is enabled on the WLC1 and WLC2, the MAc-Auth no longer works. That is, the previously authenticated user is now redirected to the Web-Auth page. The local controller shows the user as authenticated but the Anchor controller shows the state as WEb-Auth-REQD.
    Rolling back using "config mobility new-architecture disable" and rebooting resolves the issue.
    Does anyone what changes from the old to the new that would break this mac-auth/web-auth configuration?

    You should reach TAC for these sort of issues. Not many people deploying this CA setup yet & you may not get direct feedback immediately.
    HTH
    Rasika

Maybe you are looking for

  • Value in NAST table

    Hi,   Anyone can plz give me the auswer that which types of  values are stored in NAST table. Regards, Meenakshi

  • Album art still missing in Remote with 8.1

    I'm still not getting album art with the latest version of Remote (the one that came with iOS 8.1). C'mon, what's wrong?

  • No online information for the WRVS4400Nv2?

    I just replaced a defective WRVS4400N with a WRVS4400Nv2. Now I can't find any firmware, updates or other online. Where is the information on the WRVS4400Nv2? Sadly, the site and forum redesign is several steps backward in readability and usability.

  • Number of months to/from birthday

    I need to get the age of someone in years and months and have used the following to get the years - does anyone know how to get the months??? int nToday = calToday.get( Calendar.YEAR ) * 10000 +                          calToday.get( Calendar.MONTH )

  • Delete print job

    After trying to print a file from internet the printer gets stuck and it is not possible to cancel  the print job. It can be cancelled only by disconnecting the USB cable. If I copy the file to WORD then there is no printing problem. Thanks,  Bezalel