Question of encapsulation: protected attributes must be visible to child classes

Hi guys, I found the following problem of inheritance and encapsulation and I was wondering if someone could explain it to me:

Suppose you have a parent with a non protected attribute class static (I know that's a mouthful, thank you that follows).

package package1.
public class {Parent}
protected int a = 10; It's the non-static protected attribute in question
Public Shared Sub main (String [] args) {}
what logic
} / / end class parent
} / / end of main()

Now suppose you have a class of the child in another package and that you imported in the parent class.

the package2 package;
package1 Import. Parent;
Child/public class extends {Parent}
Public Shared Sub main (String [] args) {}
Parent p = New Parent();
Class c Child = new Child();

System.out.println (p.a.); should print at 10 BUT did NOT
System.out.println (c.a.); should print 10
} / / end of main()
} / / end of class of the child


My observation is that p.a. generates an error, even if, to the best of my knowledge, it should not. I think the "System.out.println (p.a.)" statement; should I print a 10.

I'm something of misunderstanding about inheritance and encapsulation? Could someone tell me if there is a problem with my understanding or a problem with the Java language?

Thanks for reading this far. I hope that you are also interested in this question that I am. : )
-Vineet Gupta
June 6, 2013

Published by: 1010389 on June 6, 2013 23:44

Published by: 1010389 on June 6, 2013 23:57

>
An important point to make, since rp0428 posted about it, is that the class of the child is in another package than the parent class. This is done deliberately for the purpose of this thought experiment. By the rules of Java, as I understand it, ANY class of the child - regardless of the package - should be able to see the protected variables.
>
Then you don't have to "understand" section of the specification of the Java language that I quoted.
>
If the class of the child was in the same package as the parent, the child would be able to see the default encapsulated AND protected variables. But if the child is NOT in the same packet, then it should always be able to see the protected variables. Isn't it?
>
No - it's NOT just as technical section I quoted said you.
>
Once again, without a concrete answer, he got to wonder if this is a bug hidden in the JAVA virtual machine. If so, my next question would be how to report?
>
You have a "concrete response." It doesn't get any more "real" than the specification of the Java language. It defines the rules and that I have cited applies to your use case.

Tags: Java

Similar Questions

  • 1013: the private attribute may be used only on class property definitions.

    In the following code, I get an error. How to solve this problem?

    Line 301013: the private attribute may be used only on class property definitions.

    package

    {

    import flash.display.MovieClip;

    import flash.events.Event;

    Caesar/public class extends MovieClip

    {

    var speed: Number;

    public void Caesar()

    {

    addEventListener ("enterFrame"), move;

    }

    public void move(e:Event)

    {

    This.x = mouseX;

    This.y = mouseY;

    If (caesar.hitTestObject (MainClip.instance.enemyList [i]))

    {

    trace ('Caesar should');

    removeSelf();

    MainClip.instance.finishedMainClip ();

    }

    }

    }

    private function removeSelf (): void

    {

    removeEventListener (Event.ENTER_FRAME, move);

    If (stage.contains (this))

    {

    this.parent.removeChild (this);

    }

    }

    }

    Check your dash... Your removeSelf function is outside the definition of the class... that closing brace entered should be after him.

  • Questions on the Dimension attribute

    1. when I look at the "Attribute" terminology on the link, it says "an attribute provides additional descriptive information about a dimension and/or specific breast of this dimension members... ", but on AWM help, he says"attributes provide information that is typically no additives on the individual dimension members. "I am confused with the word"additional"and"no additive. They have opposite meanings?

    2. it is a good example in the explanation of "Attribute" terminology on the link, for example, he said "in a database of representative of the shoes, you can use a shoe color attribute to select all boots, sneakers and slippers that share the same color. By adding these attributes of types to your data model professional users can answer questions such as: what colors were the most popular in the dresses of the women in the summer 2005? How this compares with the previous summer? ». What happens if we define color as a level, not an attribute in the hierarchy under the product level? What happens if we define color as a dimension, not an attribute? I have to say that the purpose of setting the attribute intrigues me a lot.

    3. There is an option when creating/updating an attribute: Index. AWM help, he said "Select this option to improve the performance of the queries based on the attributes.". What is a 'attribute-based queries? And when we can use?

    4. There is an option when creating/updating an attribute: attribute values are multilingual. If I check it "Long Description" attribute, for example, there are only LONG_DESCRIPTION (AMERICAN) and LONG_DESCRIPTION (ENGLISH) could be mapping. Is there a way to make more than two languages? At the same time, there was still a LONG_DESCRIPTION column in the view of dimension and hierarchy. What language data will be exposed in the view, LONG_DESCRIPTION (AMERICAN) or LONG_DESCRIPTION (ENGLISH)?

    5. to AWM help, he said "You need to map all the attributes of their data sources.". In fact even if I don't maps all attributes, the size of maintenance process always work well. So why he uses the word 'MUST' here?


    Thank you
    Satine

    Satine,

    As you have discovered, AW physical objects are not in the object view. To see the list of objects in an AW you use OLAP DML, which you can make by using the call of PL/SQL dbms_aw.execute. I'm going to assume that your AW is called GLOBAL in this example, but obviously you need to change this to your own.

    -Activate output Server (or you don't see any results)
    Set serverout on

    -Attach the aw
    dbms_aw.execute exec ("' aw attach global")

    -the list of all the objects of the AW
    exec ('listnames') dbms_aw.execute

    -This example lists only things like ' PRODUCT % '.
    dbms_aw.execute exec (' like ListeNoms ' PRODUCT %''))

    -This example lists only dimension of objects
    exec ("ListeNoms size") dbms_aw.execute

    Determination of size "on the disc" objects AW is not directly supported by the OLAP DML language to my knowledge, but the following query may work for you. Once more, replace 'global' with the name of your AW. (More precisely, to replace the table named ' aw$ global "with your aw table.)

    define lines110 500 pages
    Col aw_object for a70

    Select objname |': ' | aw_object partName, round (sum (dbms_lob.getlength ('AWLOB')) / 1024,3) KB
    AW$ global
    where extnum = 0
    Objname group, partname
    order by objname, partname

    David

  • Question about the protective mask cracked Portege M200

    Hello world

    I have an urgent question, who need your help. I have a Portege M00 tablet pc at home, and the Portege M200 LCD screen is covered with a protective mask. But yesterday I closed the laptop without notching of the pen between the screen and the keyboard. now the protective mask had been broken and the screen of the laptop is ok. So I want to know is - can I change the cracked by a new protective mask?
    Has anyone experience this? Thanks in advance!

    Hello

    I think it should be possible to replace this protective mask.
    But I put t found any offers on the web.
    I recommend you ask the service partner to help him. Maybe he can order this mask of protection for you.

    Good bye

  • Question about Bberry protect

    Hello

    I installed the application Protect, which has the following features:

    -Ups support via the web or wi - fi

    -Can map your device via GPS if lost/stolen

    -Can be banded remotely if lost in the House.

    Then... I thought to take advantage of these features, I was able to connect on a Web site, to recover back ups, tracking device on the card, device ringtone to distance, etc... But, once I installed the app, nothing tells me where to find these services remotely on the Web site. I looked on the page web, the messages app on my device once the application is installed and also did a search on Google and nothing leads me to believe that there is a site that would allow me to take advantage of these features remotely.

    Is this means that this function must be accessible through another blackberry only? Which means that if I want to find my device via GPS, I can't use an another bberry which has this request?

    Thanks for the information.

    See you soon.

    Sign in using your BlackBerryID account to this url from a PC:

    https://blackberryid.BlackBerry.com/bbid/login/?callbackuri=aHR0cHM6Ly9wcm90ZWN0LmJsYWNrYmVycnkuY29t...

  • Force an order in which LOV or the attribute must be filled.

    Experts in the morning,

    I have a case, I LOV 5 attributes, I have them set up so that each list in the menu dropdown is dependent on what is selected in the attribute above it, for example, if you select the attribute top of 'Region' in Europe, you will see no country in Europe to the LOV below him.

    What I need to do, is make sure that the second attribute and attributes of 4th and 5th 3rd later cannot be selected until the respective attribute above it has been filled.

    If the 2 attribute cannot be filled unless attribute 1 has been selected.

    Attribute 3 cannot be filled unless the attribute 2 has been selected and so on...

    Thanks in advance for your help.

    Jamie.

    Jamie, tell us your version of jdev, please!

    Each of the LOV components store their value in storage represented by the value property.  If nothing is selected, the value must be null or empty. If a value is selected (and autosubmit is true) value is not empty. You can use this information to disable subsequent LOV on the page by assigning has disabled the property to an EL as disabled = ' #{empty bindings.myLov1.inputValue) ' where myLov1 the storage of your LOV. This you can do it in any depth.

    Timo

  • All protected LUNS must be identified separately within the Group of Protection of SRM. But this isn't the case!

    Hello

    I installed the latest version of SRM in our environment. We have 2 IBM midsize v7000 storage on primary site and disaster. We use array based replication.

    I have configured groups of consistency for all LUNs replicated through v7000 storage.  All LUNS are replicated successfully. I installed the last IBM midsize SRA on two SRM server. There is no problem...

    Everything is ok. But; When I try to create protection MIS group, I couldn't see LUN separately. If you look at the images below, you will understand what I mean;

    I have four different coherent group on v7000.

    3.jpg

    The SRA has been installed successfully.

    1.jpg

    I see all the cohesive group of v7000 under the SRA through SRM.

    2.jpg

    IT'S MY PROBLEM! All LUNS must be separately! But I see a group of data store! It must be like on the right side. I want to create different Protection Group all LUNS. But I couldn't choose lun separately.

    who knows what is wrong?

    4.jpg

    Thank you.

    Check if any of your virtual machines have VMDK on all LUNS, because you'll be able to create a Protection Group separately for each single logic unit number if a virtual have virtual disks on more than one logical unit number.

  • Question of VSphere licenses (attributed more CPU than actually)

    Hello!

    I have three licenses of business (1 to 6 cores per processor) of vSphere 4 with different capacities. And I have a problem with both of them. In VCenter license page shows me that a license assigned to 6 CPU, but its actually attributed only to 4 CPUS (two ESX servers with two cpu's (4cores) of each). And another licensed showed as assigned to 16 CPU, but actually his attributed only to 14 CPU'. This license has a total 16 CPU capacity and that's why I can't add another a host ESX to my Infrastructure. And with last license, I have not any problemms. Why it might be so? Please help me if you know how to solve this problem.

    Try to remove ALL licenses and add them.

    If this does not work go to your portal vLicense on VM Ware, regenerate the NEW keys for your existing licenses and remove existing keys in vCenter, and then ADD the new that you generate.

    You can split a license and then join them that will make new keys.

    Otherwise, you must call the vmware support and ask people to licensing to help you.

  • Questions of frequency wireless network (must be 2.4 MHz!)

    I just spent two weeks of struggling to get my new Photosmart Premium (C309g) to join my 802.11n network.  At one point I even learned by HP phonesupport that this model is only compatible with 802. 11 b / g and that's why the model number ends with 'g '.  Fortunately, not proven to be true. In fact, this product works as advertised, with a warning not to disclose:

    MUST BE ON YOUR 2.4 GHz WIRELESS NETWORK.

    I got my network configured to operate at 5 GHz.   I changed it to 2. 4 GHz, and now my Photosmart Premium works perfectly.

    What a pity that this minor detail is not in one of printed or online technical documentation of the manufacturer. If all goes well in sharing this information I can save someone else to go through the frustration that I did.

    I can't believe that our support officer told you that the g in g 309 means the printer only 802. 11 b / g compatible.  It's not that the suffix in the model number means.

    By definition, 802.11n devices are compatible with the networks of 802.11 g (as vice versa) as long as they are on the same frequency (2.4 GHz or 5 GHz) band.  Currently, all of our 802.11n printers operating in the 2.4 GHz band only.

  • The question of stamp protection

    I created a stamp to ensure the tightness of my engineer and signature but I use it for all the documents must be registered so that no one can open the file and select and copy my seal. This used to be very easy to do, but with this new "improved" Acrobat version, I can't understand how do. He has been recording as a file high ground would make the case, but that seems to have disappeared now.

    Hi Ggunn1-

    You can use an action to flatten the stamp when it was applied. In this way it becomes an integral part of the content of the document and cannot be selected separately from the content of the page. Your stamp and then follow these steps:

    1. At the top left of the screen, click Tools to load the Tools page in the document window.
    2. Click the field of Search and type preflight.
    3. The contents of the filter to the upstream control bodies - click on one of the icons.
    4. Charge of the preflight dialog box. You can scroll through the list, or click on the upper left field and choose the PDF corrections (shown in the figure below).
    5. Click on flatten annotations and form fields to select it and then click Analyze and fix.
    6. Acrobat processes the file and flattens your stamp.

    Donna.

  • still gives Adobe error 19 "video stream main attribute must be consistent within plays list

    Anyone know what this means, when burning Blu Ray discs?

    Yes.

    This means exactly what it says - the primary stream must be consistent.

    On Blu - Ray, a video timeline is a playlist. Still, it is possible to put several clips in a timeline, and these must be the same.

    Same type of video & format

    Same Audio type & format.

    Do you have a calendar with multiple clips on them?

  • question on the [ILO] attribute definition for the products in the file MXI (bug?)

    Hello

    When I set the attribute [bit] of a product in xmi (set to 64) of the file and create the package, Adobe extension manager CS6 refuses to install on a 64-bit system (saying :) because it is a 64-bit extension!

    I tried in two different environments (Vista and 8-64 / CS6) with the same result!

    Is this a bug (known?) or I do something wrong?

    <product version="8" maxversion="8" primary="true" name="InDesign" platform="win" bit="64"/>

    Any idea would be appreciated, thx, mim

    The attribute bits, the version of Win32 or Win64 of the product for which this extension can be installed. It has nothing to do with the Windows operating system architecture. Since InDesign CS6 has 32-bit version of Lara, you don't have to specify as "64" bit, even if you use 64-bit Windows.

    From CC, InDesign has 32-bit and 64-bit version on Windows. But they have the name of different product, "InDesign" and "InDesign64" respectively. So if you only want to create 64-bit InDesign CC extension, you can specify:

    The 'primary' attribute is no longer used on the CC. The name of the product of InDesign on Mac is still 'InDesign', 'dilated' and 'bit' attributes are not necessary to specify in this case.

  • Question on the % NOTFOUND attribute slider

    Here is my PL/SQL:

    OPEN FOR C_original_demo
    ' SELECT pro_flags, spo_flags, proemp_flags, spoemp_flags
    OF test.original_demo
    WHERE id_number = "< any id > ';
    EXTRACTION c_original_demo
    IN v_pro_flags, v_spo_flags, v_proemp_flags, v_spoemp_flags;

    IF c_original_demo % NOTFOUND THEN
    v_pro_flags: = '0000000000000000000000000';
    v_spo_flags: = '0000000000000000000000000';
    v_proemp_flags: = '00000000000000000000';
    v_spoemp_flags: = '00000000000000000000';
    END IF;

    When the code runs, it bombs on an ID that doesn't have a record in the original_demo table, if his tent of extracting any data in my variables. But which is not what the % NOTFOUND logic is supposed to prevent? I use it wrong?

    Thanks for the help,
    ivalum21

    Hello

    I think that must be reported

    ID_NUMBER NUMBER(some value) 
    

    Thank you

  • I can't play movies remotely. Is it a question of copy protection?

    original title: WMC

    On one of my remote laptops, I can see and play all the TV recordings except movies.  Is this a copyright thing or what?  Is it possible to play movies recorded?

    LOLz.  Happy that you got including (and it was simple.)

    To the best of my knowledge, there is no way to read a disk (on the server) to a client.  But, you can play torn discs.
    Some MC users swear by the media browser for this purpose; others swear by MyMovies.  I like MyMovies.  I have installed on my main MC client/server and the client installed on my desktop & laptop.  I can manage the collection of any one of them and all my rips play on any of the three, as well as my two Xbox 360 (running as Extenders to the main MC.)

    Now, tear may be a bit of an art (and there are a lot of personal preference, too.)  I rip a movie (main title only, w / English 5.1 or better acoustics) using DVDFab (free); I then point video again (currently 75 $US for Suite TV, you need to do this) at the level of the rip and that convert DVR - MS.  In this way, I maintain full compatibility with all what I use and keep the FF/Rew features on the extensions.

    You can rip & convert to many other formats (AVI, WMV, or leave as mi/gal) with other (and free) tools; but Extenders are limited in what they can play natively (or, with playback controls complete.)

  • Questions on the computer stop, must try to stop twice

    Original title: twice to close...

    Windows xp-Dell Latitude E6500... when I try to shut down or restart, I have to try twice before his arrest... What's wrong?

    Hello

    Remember to make changes to the computer before this problem?

    I suggest you to disconnect all external devices such as printer, scanner, etc, that are attached to the system and check if the issue persist.

    Follow these steps:

    Method 1: I suggest do you a clean boot and check if you are able to close download the computer correctly.

    How to configure Windows XP to start in a "clean boot" stat
    http://support.Microsoft.com/kb/310353

    Note: -after troubleshooting, turn on the computer to a normal startup.

    Method 2: Advanced Troubleshooting for shutdown problems in Windows XP

    http://support.Microsoft.com/kb/308029

    See the article:

    Windows unresponsive during Windows XP stop dow

    http://support.Microsoft.com/kb/307274

Maybe you are looking for

  • Where is the CD-IN header? (dc7800 CMT)

    Hello. I use a computer in minitour dc7800 Convertible and have a question. Is could someone please tell me where the CD-IN header on my motherboard? There must be 3 or 4 pins. I don't know well it is not necessary for football on a CD, but it's for

  • Equium A200 - how to get the operating system?

    Hi, my son has just been given an A200 and we put in place a new disk hard in, but we do not have the recovery disks. Anyone know how I could get my hands on copies or how to download the operating system and then is just a matter of inserting the di

  • Equium A60 problem overheating and stand-by

    Yes, again, someone else has a problem with overheating Equium. I thought and knew that it was a foul, I checked the CPU and it looked like 2-4% and the fan still worked riot. But recently, I noticed when I press ctrl alt del to remove the Manager ta

  • T60 camera?

    Hello made all t60 don't have the camera?

  • ACER Aspire 5630

    I got an ACER Aspire 5630 computher a friend.  The OS is Vista Home Premium. The DVGW TS - L6320 CD TST Corp isn't funcational.  I have remove the devices from the Device Manager.  Rbooted and during the driver installation failed.  This disc is inop