Protected variable accessed by non-subclass in same package!!!!

In Java - Complete Reference, I have read one thing, which I feel breaks the rules of Object Orientation.
It states that, a protected variable can be accessed by a class which is non-subclass of that class, but is in the same package.
Strange!!!
Then what's the difference between subclasses and non subclasses in the same package!!!!
please comment!!!

In Java - Complete Reference, I have read one thing,
which I feel breaks the rules of Object Orientation.
It states that, a protected variable can be accessed
by a class which is non-subclass of that class, but
is in the same package.
Strange!!!No, this is good and proper. A package is like a slightly wider version of a class. Classes in a package collaborate closely together, but are not quite so tightly coupled as to all belong in a single class. A subclass is not that closely connected to the parent class. From the subclass' perspective, the stuff in the parent's package may as well be private stuff in the parents class. The stuff in that package is stuff that no other class outside that package needs to know about.
>
Then what's the difference between subclasses and non
subclasses in the same package!!!!It's quite common for subclasses not to be in the same package as the parent. More common than to be in the same package, I'd guess. A subclass is a specialization. A special kind of the parent class. It's the same in its overall purpose and behavior, but may add a bit of specialized functionality, or do some things in a specialized way. Classes in a package, on the other hand, are intended to work together much like methods in a class--outsiders need not see all the details, but internally they can all see each other.

Similar Messages

  • Protected variable access | Compilation Error

    package certification;
    public class Parent {
         protected int x = 9; // protected access
    package other;
    import certification.Parent;
    public class Child extends Parent {
         public void testIt() {
              System.out.println("x is " + x); // No problem; Child inherits x
              Parent p = new Parent(); // Can we access x using the p reference?
              System.out.println("X in parent is " + p.x); // Compiler error!
              Child c = new Child();
              System.out.println("X in parent is " + c.x);
    }Why the error when I create a Superclass object in subclass and try to access the superclass protected variable through it.

    Specifications says the following about protected members access : "A protected member or constructor of an object may be accessed from outside the package in which it is declared only by code that is responsible for the implementation of that object."
    (�6.6.2 "Details on protected Access", illustrated in �6.6.7 "Example: protected Fields, Methods, and Constructors")
    In your example, p is of type Parent, and the code is not responsible for the implementation of it.

  • Accessing other classes in the same package

    I have the following two classes in the same package. Why cant I access the myString vairable from Test2 like I try and do below?
    package test;
    class Test1 {
         public static String myString = "Hello world";
    package test;
    class Test2 {
         static void printMe(){
              System.out.println(Test1.myString);
         public static void main(String args[]) {
                   printMe();
    }

    Why when I take the "package test;" line of code away I can compile it normally?This depends on how you call the compiler and how you have set the class search path. Classes that are in a package are expected to be found from some place in the search path under a directory that has the same name as the package. The default class path consists of only the current directory, ".", so you can avoid all problems by compiling and running from the directory above "test" rather than "test" itself.

  • Cannot acess classes in the same package.

    Hi
    I have "a.java" in c:/java/test directory. I have "b.java" file in the same directoty which creates a instance of "a" class. "a.java" compiled fine. But when compliling "b.java" i get error message
    cannot resolve symbol
    symbol : class a
    I have used "public" as acess modifier for both the classes. As per rule I can access the classes in the same package. But for some reason my program is not compiling. Can anyone tell me what the acutal problem is.
    Thanks in advance.

    Javapedia: Classpath
    Setting the class path (Windows)
    How Classes are Found
    java -cp .;<any other directories or jars> YourClassNameYou get a NoClassDefFoundError message because the JVM (Java Virtual Machine) can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.
    javac -classpath .;<any additional jar files or directories> YourClassName.javaYou get a "cannot resolve symbol" message because the compiler can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.

  • Can one obj access a private variable of another obj of the same class

    Can one object access a private variable of another object of the same class?
    If so, how?

    Declaring variable private means you can not access this variable outside class
    But other objects of same class can access it. Because each object have separate copy of variable and may have diff. contents for same variable.

  • Don't touch my protected variables!

    Most of us will know that encapsulation is a good principle; if other objects could manipulate everything in every other object it is much harder to keep objects in a valid state and easy to create incredible spaghetti code....
    One way of encapsulating variables and methods is by using the protected scope. This means that no one can touch the variable or method except subclasses which inherit from the class. Ok, you got me, I just LIED to you. Protected variables and methods can still be manipulated by classes inside the same package!
    Does anyone know why Sun made it this way? Why is there no scope modifier that is in between private and protected that does exactly this?

    markwagoner wrote:
    Well you also have package-private, but this allows classes in the same package access but not subclases.
    I think the reasoning is that, generally, classes in the same package will all work together (hence being in the same package) while subclasses work primarily with the superclass.
    This may explain it better
    [http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html]
    IMO even if they work together they should never touch each others variables directly but only by using methods. By accessing a protected variable of another class inside the package this is scarily close to using public variables!
    Thank you for the link, there is a very clear table there. What I meant was something like "inheritable":
    Modifier      Class      Package      Subclass      World
    inheritable Y N Y N

  • Access to non spatial tables in oracle mapviewer/ oracle maps V2

    Hello,
    We want to have access to non spatial oracle tables (for value list creation etc), existing in oracle mapviewer spatial datasource (ex datasource: MVDEMO/ nospatial table: Employees).
    We have allready created the datasource MVDEMO and we want to avoid the creation of an external datasource to the same oracle user.
    Thxs,
    Bill

    Thanks.  Your answer was very helpful.  It pointed me in the right direction.  I wanted to be able to generate a table, below the map, which listed all the points (and their associated data) shown on the map.  The simplified code I used is shown below.  The function is called using an event listener (map.addListener(OM.event.MapEvent.LAYER_ADDED, createTable) which fires after the pointlayer is added to the map.
    function createTable(evt) {
        var tableRecords = pointLayer.getAllFeatures();
        var tableRecordsAttr = pointLayer.getAttributeNames();
        divElem = document.createElement('div');
        tableElem = document.createElement('table');
        tbodyElem = document.createElement('tbody');
        rowElem = document.createElement('tr');
        // create the table headings     
        for (var i = 0; i < tableRecordsAttr.length; i++) {
            colElem = document.createElement('th');
            colElem.appendChild(document.createTextNode(tableRecordsAttr[i]));
            rowElem.appendChild(colElem);
        tbodyElem.appendChild(rowElem);
        // populate each row of the table with data
        for (var i = 0; i < tableRecords.length; i++) {
            rowElem = document.createElement('tr');
            for (var j = 0; j < tableRecordsAttr.length; j++) {
                colElem = document.createElement('td');
                colElem.appendChild(document.createTextNode(tableRecords[i].getAttributes()[tableRecordsAttr[j]]));
                rowElem.appendChild(colElem);
            tbodyElem.appendChild(rowElem);
        tableElem.appendChild(tbodyElem);
        divElem.appendChild(tableElem);
        document.getElementsByTagName('body')[0].appendChild(divElem);

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

  • HELP Cant login on my MAC after changed in OSX Server all access for NONE

    Hi
    After changed for the users , roots , and another one , the access for NONE in one of the options in  OSX Server to configure access just lost the capability to open the programs with the click of the mouse and turned off the MAC
    I can't login now into my MAC , the display got the apple logo on startup and the login window doesn't come blocking me to login
    Any help are welcome
    Thanks 

    Hi
    Just tipped command key and S key and hold it and turned the mac on
    Lots of information coming but in the middle of the screen I can read some of the lines it says
    Darwin Kernel VErsion....
    Security policy loaded
    AppleIntell CPUPowerManagementClient :ready
    FireWire (OHCI) TI ID 823f built-in is now active
    Got boot device= iOService : AppleACPIPlatformExpert ......
    "Launch [1] has started up in single-user mode"
    " Verbose boot will log to /dev/console "
    "SHutdown loggin is enabled "
    Root device is mount read-only
    It got much more lines and ends with
    If you want to make modifications to files
    /sbin/fsck -fy     ( this command line show that system it's ok )
    /sbin/mount -uw
    If you want to boot the system
    Exit
    But after exit it goes to the same situation with the apple logo in the middle of the screen and the login widow doesn't come
    Thanks anyway for your answer
    Any further information in how can I login into my mac are welcome
    Thanks

  • Accessing multiple portals at the same time?

    Is it possible to access multiple portals at the same time?
    For example, what I want to achieve is different properties (layout,
    portlets, look & feel) for different groups of users accessing the same
    portal. The Associated Groups part on the Portal admin page is not
    fulfilling our requirements. So we decided to have different portals for
    different groups of users, all working through one portal, and accessing
    their custom portals. Is this achievable?
    What we are thinking is: put the common functionality in the repository
    portal directory, and the custom portlets/jsps in the group-specific portal
    directories. This way we can customize portal behavior for different groups
    of users. Is this achievable?
    Thanks.
    Amit

    You have to user respective DRILL commands present in WAD to configure the drill operations on multiple characteristics...

  • Is there a way to password protect internet access?

    Is there a way to password protect internet access?
    Is there a way to password protect the Airport function on my mac?
    I have spent some time looking at the forums and on the internet trying to look for a app that can solve my problem. I wish to be able to turn off internet access. I have been using K9 web protection but have found some flaws and bugs. It is a great idea and works well except for the "block any access between(set time) and (set time)" function.
    I want to be able to use my computer with out the worry of access to the internet. In my simplistic ideas I need an app that will simply toggle the AirPort function on and off and password protect it. That way when i dont want the distraction in my own life and when i let the rest of the family are playing games the internet is safely protected.
    At this time the ethernet connection is not a problem.
    I can simply un plug the router however the neighbours around me don't password protect their connections!
    If any one knows of a way to solve this or any alternative solutions please let me know.
    Many thanks for reading and I look forward to your expertise.
    Alex

    AirPort Express frequently asked questions (FAQ)
    Question: Can I completely turn off the AirPort Express wireless signal when I don't need it?    Answer: No, though you can turn the transmission strength down to a minimum setting. To prevent unauthorized access, you can turn on wireless security features.
    http://support.apple.com/kb/HT1515
    Wi-Fi base stations: Setting up and configuring a roaming network (802.11 a/b/g/n)
    http://support.apple.com/kb/HT4260
    Check your access privileges
        If you enabled encryption on your network, make sure that you set up your base station or router properly. Consult the documentation that came with your product. Make sure you're using the correct settings and password. If you're joining a closed network, a network with its name hidden, make sure that you've entered the network name and password correctly. If the network is secured by access control, make sure that your MAC address is registered with the network administrator. Consult the network administrator for assistance with access.
    http://support.apple.com/kb/HT1145
    Airport Apple Support
    http://www.apple.com/support/airport/

  • Thanks all for the great advice.  Another question.  If I use Entourage on my desktop Mac to access an email address I use on there, is it possible to be able to access my email on that same email address on my iPad either with or without Entourage?

    Thanks all for the great advice.  Another question.  If I use Entourage on my Mac desktop to access my mail using an email address I have on there, is it possible to access my emails on that same email address on my iPad, either with or without using Entourage.  Is there an Entourage app, or something I could use?  Thanks...

    Simply add the email account to Mail, no need for Entourage.
    One word of warning, though, iPads tend to become community property (meaning anyone who uses your iPad can access your email). That is why I have zero email accounts on my iPad.
    I use Entourage on my desktop as well, so going back and forth between Entourage and Mail (whether on your iPad or iPhone) is no problem.

  • Accessing Time Capsule on the same LAN ?

    I've placed my Time Capsule on the same LAN as my other systems (a switch) -- I cannot access the TC on the same LAN, only if I plug my Mac in the switch ports behind it.
    How can I reconfigure the TC to allow connections to it on the external LAN? In front of it is a firewall, and I don't want and double NAT configuration.
    Thanks.

    You just need to reconfigure the TC as a bridge. (ref: AirPort Utility > Manual Setup > Internet > Internet Connection > Connection Sharing = Off (Bridge Mode))

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

  • Access Connections - Many APs with same SSID (Again)

    I have a W520 running Access Connections 6.11 (release December 2013) on Windows 7 Pro 64-bit.  Access Connections is still broken in regards to dealing with multiple Access Ponts having the same SSID.  It keeps hoping from one access point to another regardless of signal strength of the AP.  
    The most desirable strategy would be if Access Connections would find and lock on to the best signal strength AP and stay there.  However, it doesn't do that.  It acts almost randomly.  It also keep shifting around.  The rate is almost random as well.  Sometimes it will stay locked on to an AP for up to 10 minutes, at other times it shifts in as little as 30 seconds.
    Other laptops, from other manufacturers like HP, Toshiba, and Apple do NOT exhibit this behavior on our campus.  Other Lenovo machines running Access Connections DO exhibit this behavior.  The problem is NOT machine specific (ie, not hardware or some weird idiosyncracy of the particular W520 i'm posting about).  The problem is Lenovo's Access Connections.  The problem is also not a configuration issue with the campus.  I have a network at home running Airport Extremes all having the same SSID's and the W520 in question does exactly the same behavior there.  Totally different hardware at home vs campus and same behavior.  I cannot change the names of the AP as a fix.  This is not a capability in the configuration of the AP's.  Even if it were, I shouldn't have to do it.  Campuses are often configured in this way.  Campuses that are large commercial users who I believe are the most lucrative Lenovo customers.
    This problem has been going on for literally years with different versions of Access Connections.  Here are two threads in the Lenovo Community I found in under 30 seconds.  Neither was solved correctly.  In other words, Lenovo never fixed the software, and people had to either give up or resort to kludge solutions in their campus configurations.  
    http://forums.lenovo.com/t5/ThinkVantage-Technologies/Is-it-possible-to-default-to-a-specific-Access...
    http://forums.lenovo.com/t5/ThinkVantage-Technologies/Access-Connections-Many-APs-with-same-SSID/m-p...
    Lenovo has actually made the problem progressively worse over time instead of fixing it.  They have done this by removing the abilty to prioritize AP's by MAC address.  Initially, Lenovo allowed you to configure 5 MAC addresses in order.  Then, Lenovo removed that capability making it possible to only give a single MAC address as preferred.  Finally, in recent iterations, Lenovo removed that capability alltogether.  The box is still there in the UI, but it's greyed out.  It is very frustrating to have this kind of thing happen.  The prioritize capability is fundamentally a kludge, but at least it's something to give a bit of a workaround.  Now we don't even have that.
    Can a lenovo engineer please look at this issue and give me a timeline for resolution?
    BTW, It is still not possible to configure Access Connections with a blank SSID either.  I bring this up, because if you're going to fix the Access Connections code for multiple SSID's, you should be aware of the blank SSID problem as well.  I imagine they are both in the same part of the Access Connections codebase, at least from a logical standpoint.
    Thank you.

    I found that there is a setting in the Intel driver (15.9.1.2, released 8/22/2013) for the wireless card (Centrino Advanced-N 6205).  The setting adjusts the "roaming aggressiveness".  I can only guess this means how often the driver goes out and tries to find a "better" signal and/or bandwidth.  The card supports a/b/g so the calculus is complex as to what constitutes "better", and I have no idea how sophisticated the algorithm the driver uses is.
    That said, if I set the "aggressiveness" to the most aggressive setting, things work somewhat better.  They are still not as a good as other wifi managers bundled with competing products (specifically HP, Toshiba, and Apple so far), but it helps.  It does appear that more of the time now, the AP having the best signal appears to be the AP the laptop is attached to.
    Lenovo, please consider that forcing your customers to dig around in arcane driver settings and relying on the whims of driver writers and hardware companies to do things correctly and well, is a recipe for failure.  Your customers are just going to get annoyed and say to their colleagues, "My old Toshiba seemed to do a better job of WiFi connections. I think next time, I'm going to have IT get me one of those again."   And, of course, that colleague will look a lot harder at buying the Toshiba instead of the Lenovo, as well.  Wifi connectivity is a very big deal for people who have to move around - and lets not forget, this is a laptop we're talking about, which is explicitly designed to, well, be moved around.
    I apologize for being so pedantic, but it often takes such measures to get managers in these companies who control programmer time, to take these issues seriously and allocate the programmer resources to fix these problems.
    The problem I am having is still not considered "fixed."  I would very much like to hear any other solutions that work better.  I would love to hear from Lenovo on the matter.  Still waiting.
    Thanks.

Maybe you are looking for

  • On iMessage, if someone sends me a photo I can't see it? How can I see them?

    If someone sends me a photo on iMessage I can't see it, and it sometimes comes up with "message delivery" or something similar to that. How can I see these photos?

  • Not able to stop Resource group

    I was not able to bring the resource group to offline.. Since some of resources are in stopping state and hung there. I was not able to either bring the resource to offline nor the resource group. ============================================= Output

  • Looping issue and extra space after inserting in DW page

    I found an answer to looping an Edge composition, works like a charm in publish preview, still won't loop live on the web. Also when I insert it, it leaves a gap at bottom even though the div is 250 px high and the composition is 250px high... see ww

  • I have PO number

    I have PO number created for test, i need to get IDOC number and feilds values also vendor id. How i can get it? And in which system i have to check in ECC or in XI?. Please do needful. Thanks,

  • Newbee question (first of many though)

    As soon as I can break through the initial intimidation I hope to begin learning Lightroom and cataloging my 15k+ images.  Before I dive in though I'd like to begin with a handful of images and see how the program and my workflow (to be determined) w