Why Java doesn't allow to reduce the accessibility of a method du

Why Java compiler does not allow to reduce the accessibility of a method during inheritance?
( Eg; If the base class has a public method and if that method is overridden in child class but
with defuault access, it gives compile error)
Supposed answer:
Because in the runtime, it cannot check the access modifier.
Suppose A is the base class. It has a method fun() as public.
B is the derived class of A.
Suppose in some other class (say C) there is a method myFun() which takes A as parameter and
calls the fun() method of A. So that method can take B
also as parameter (As it is derived from A).
So if the fun() method's accessibility is reduced in B, whether "that can
be called in C or not" is not known. that is why compiler does not
allow the reduce the accessibility of a method during inheritance.
Member variables do not have this problem as they can be checked at
compile time.
Is this explanation correct?

You can give private access, sort of... you could fake it, if the goal is to prevent someone from doing what the method does. Of course, they could (as long as A isn't abstract) create their own A and do whatever they want.
class A {
   public void doThis() {
class B extends A {
   public void doThis() {
      // explicitly do nothing
}But I think generally, this shouldn't be a problem. I'm not sure if it's something that is common for creating an API to subclass another class to hide the superclass's methods. Usually you are adding functionality to a subclass that is for more specific things then the superclass supports. I mention creating an API because if it's just for some application class, then you are writing it, so use or not use the methods as you want. It's APIs for library type classes that other people would use, and if you are extending the library, and really need people not to call methods for some reason, document it. Maybe a good place for an assertion?

Similar Messages

  • HT1694 My hotmail access disappeared from my iPad. When I go to settings and click 'mail, contacts, calendars' the page freezes. It doesn't allow me to the account setting. Anyone have suggestions?

    My hotmail access disappeared from my iPad. When I go to settings and click 'mail, contacts, calendars' the page freezes. It doesn't allow me to the account setting. Anyone have suggestions?

    Your Settings app is crashing. Sometimes, the only way to fix this is by restoring the iOS software but hopefully it will not come to that.
    1. Quit the app completely and restart the iPad. Go to the home screen first by tapping the home button. Double tap the home button and the task bar will appear with all of your recent/open apps displayed at the bottom. Tap and hold down on any app icon until it begins to wiggle. Tap the minus sign in the upper left corner of the app that you want to close. Tap the home button or anywhere above the task bar. Restart the iPad.
    Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.
    2. Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons.
    3. You can try resetting all settings. Settings>General>Reset>Reset All Settings. You will have to enter all of your app preferences and device settings again.

  • My iphoto doesn't allow to share the photos to facebook anymore. (publish button doesn't work) does anyone knows what is wrong?

    my iphoto doesn't allow to share the photos '09 (8.1.2)  to facebook anymore. publish button doesn' work. (it used to be OK) anyone has any idea?

    There are a couple of things that could be causing this. Try:
    delete your iPhoto cache
    hold down the option key
    in the Go menu in the Finder, scroll down to Library
    in Library, find Containers/com.apple.iPhoto/Data/Library/Caches/com.apple.iPhotoin that folder, find Cache.db and drag it to the trash.
    delete the iPhoto preference file
    do the same trick with the option key to show ~/Library
    in Library/Preferences, find com.apple.iPhoto.plist, and drag it to the trash
    if there are multiples of any of these files, drag them to the trash too.
    delete the Keychain entries and do Keychain First Aid
    in Applications > Utilities > Keychain Access
    in the column on the left select login and under category, Passwords
    delete all of the entries that include iPhoto or Facebook
    in the Keychain Access menu, scroll down to Keychain First Aid, enter your user password, select repair, and click start.
    Then restart your computer
    new caches and preference files will be generated
    you will need to reenter your iPhoto preferences
    reenter your facebook user name and password in iPhoto
    this should fix it.
    Message was edited by: arthur

  • Why java is giving 'attempting to assign weaker access privileges'  error?

    Can some one can tell me why java is giving 'attempting to assign weaker access privileges' compile error while compiling Abhishekchild.java ?
    The two classes is :
    public class  Abhishek {
           void asd()
         System.out.println("hello");
              static String a;
              public static void main (String st[])
    public class  Abhishekchild extends Abhishek {
         private  void asd()
         System.out.println("hello");
              static String a;
              public static void main (String st[])
    }In my opinion, java compiler is showing the error , as method asd has public visibility in Abhishek. java so
    (i)it should be visble to all sub classes of Abhishek.java.
    But if we override this function in Abhishekchild.java, and change the visibility to private then it will not be available for child of Abhishekchild.java. But these children are also children of Abhishek.java*, but this violates rule (i).*
    So java shows a compilation error.

    public class Parent {
         public void asd() {
              System.out.println("Hello");
    class Child extends Parent {
         public void asd() {
              System.out.println("Hello from child");
         public static void main(String st[]) {
              Parent parentReference = new Child();
              // The reference 'parentReference' knows about Parent.
              // Parent has a public method asd, so below code looks ok.
              // But if child could set the method to private,
              // invoking the code below, would hit the object Child,
              // where asd() is not accessible - and everything fails.
              // Note - the compile visibility is checked according to
              // the reference, not the object itself.
              parentReference.asd();
    }See my comments in the code.
    - Roy

  • P.O is allowing to reduce the quantity even when inbound del. exists

    Hi Sap Gurus,
    The P.O is created for quantity 60 and Inbound delivery exists for the P.O for quantity 60. The unlimited indicator is set in the Delivery tab of the item details. when I am trying to reduce the quantity in the P.O its allowing me toi change with soft warning message even when Inbound delivery exists for P.O.
    The soft warning message is as follows.
    60 EA (LA) already confirmed for item 00010.
    Message type__________ W (Warning)
    Message class_________ ME (Purchasing: General Messages)
    Message number________ 545
    Message variable 1____ 00010
    Message variable 2____ 60
    Message variable 3____ EA
    Message variable 4____ LA
    I tried to change the message from warning to error in system messages for purchasing but I had no success with it.
    I need to change this warning message to error.
    I would appreciate if someone encountered this type of problem ..
    Thanks in advance.
    Edited by: sspven on Jul 14, 2010 5:36 AM

    Hi,
    You were created PO with Qty of 60.Then you have posted confirmation with inbound delivery note of against PO with 60 Qty.
    Even though you have set the unlimited tolerence in the PO, you have Posted the inbound delivery note from vendor it means confirmation of receiving at your plant site. After confirmed the 60 Qty, how system will allow to change the PO qty ? ( That's why system will through the warning message it means that already confirmed quantity at plant site with inbound delivery note).
    Usage of unlimited tolerence set, while receiving stock in MIGO if vendor send excess material you can post in your plant. System will allow to post the excess qty when unlimited set in PO. 
    As per the business process once received (Picked and confirmed the qty in VL31N ) it is meaning less to change the qty in POs,
    If you have done changes in POs, you will refer the PO number in MIGO insted of inbound delivery note.
    Thanks,
    Thiru

  • Why does not safari allow to keep the zoom level over the whole website? This is universal problem for all ipad browsers.

    This is a big problem on sites like Tomshardware and Sweclockers and probably many more that Safari is not capable of keeping the zoom level the same over all website pages. And it makes the browsing experience on the IPAD an annoyance.
    You have to constantly double tap to see the website clearly for each webpage load. There should be settings to allow to remember the zoom level
    for a whole website. So you don't have to double tap on every new page of the website.
    The other browsers like ICAB and Mercury are not handling this any better and seem to be limited by the webkit rendering options available.
    It's instantly visible on Sweclockers and it becomes a problem on tomshardware when you click on a review link.
    I have included pictures here that showcase the problem.

    We are all just your fellow users here. If you intended this as a suggestion to Apple, your best bet would be to submit it at this link:
    http://www.apple.com/feedback

  • Hello, I want to change my ICloud storage (to reduce it) and don't know why it doesn't allow me.. need some help!

    So 2 weeks ago I change my storage for mistake and then I realized that It was unnecesary to have 20 GB so I tried to go back with the purchase but when I put 5 GB back i can't press "OK" button.. don't know why...
    I attach an screenshot
    Tnks

    It will revert to the 5GB allowance when your current purchase ends.

  • Why apple doesn't allow the users just to add more photos from our pcs instead of requiring us to re-sync the existing albums? I can't sync additional photos cause I have my pc  reformatted. =( is there any other way to add these photos? please help me.

    I can't sync additional photos cause I have my pc  reformatted. =( is there any other way to add these photos? please help me. these existing photos are very important to me. ='((

    Apple has not saidwhy they did it that way and it is against the terms of this forum to speculate on the reasons. It says not to:
    "Discussions of Apple policies or procedures or speculation on Apple decisions."
    The are third-party programs like TouchCopy that I think will allow you to do what you want.  You can import photos via DropBox.  The third-party programs will I know allow you to transfer the photos to your "new" computer.

  • Why Safari doesn't want to load the page of an online game ?! i never had problems with that before !

    Hello! my name is Arina!  I have an online game that i like to play named DarkOrbit ! since the last update of Safari .. the browser says it will remember my name in the game and my password but it doesn't .. and this is just for this game, don't have this problem with Facebook or yahoo mail or so ! Please tell me if is the game's fault or Safari ?
        Thank you. Arina

    You can try to (re)install the current Firefox 17.0.1 release if it isn't working with the current Firefox 18 beta
    *Firefox 17.0.x: http://www.mozilla.org/en-US/firefox/all.html
    Clear the cache and the cookies from sites that cause problems.
    "Clear the Cache":
    *Tools > Options > Advanced > Network > Cached Web Content: "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Tools > Options > Privacy > Cookies: "Show Cookies"
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance).
    *Do not click the Reset button on the Safe mode start window or otherwise make changes.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • Why it doesn't let me get the 30 day trial or download it from my laptop?

    I tried to get the 20 day trial but it says "try again later" im on my laptop but it doesnt let me get the 3o day trial and download it

    Restarting you computer may help. The correct part of the forum this question is actually the CC sub-forum. Adobe Creative Cloud
    Benjamin

  • Bridge doesn't allow me to turn on color management

    Any idea why Bridge doesn't allow me to edit/turn on color management? When I go to Edit>Creative Suite Color Settings I just get an error. Says I must launch at least one qualifying CS product. As I have Dreamweaver CS5.5 and PS CS5 running I never know what the issue is. Any ideas? Adobe help is useless on this.

    If that is the case, Adobe needs to do a better job in how the settings function. For example, instead of just getting an error message with a confusing statement, the message would provide further clarification and also solutions. The message says one needs to have at least one program running to set up color management. It doesn't say one entire color suite. But thanks so much for responding to my questions.
    A bit of the problem is that writing a manual and a help file is not that easy at all. But when it comes to complicated applications like PS and combined with other applications it really is a difficult task. I'm not saying Adobe succeeds clearly in this task because it is not easy to find your way in the new help files but with a bit effort you will soon explore there is a lot of information about understanding color in the PS on line manual (use the menu help / Photoshop Help and your browser shows a page from product support. Top right above there is the option to download the PDF manual.  And in the provided list on your browser window you see also the option for Creative Suite, click on it and you will see a complete chapter about Color Management.
    While I know a bit of this subject I'm certainly no expert. It is a complex matter but the basics are not that difficult and the result of your learning effort will pay it self back
    Another issue I have noticed is that Bridge does not do a good job at updating thumbnails. I frequently have to hit F5 to refresh when this should happen automatically. I use a Windows 7 machine and perhaps all of this works better on Macs - I don't know.
    That should not be needed on either Mac or Windows. While no knowledge of Windows at all to me it seems related to a cache problem. First point Bridge to the folder that gives you this problem and then choose the menu Tools/ cache / purge cache for folder. See if this gives better results. If so and you have other folders with same problem use the option to purge the entire cache and have a fresh start. You need a bit of time because all thumbs and previews have to rebuild.

  • Shipment Output Determination: Sold To Party needed in the access seqeunce

    Hi Gurus,
    I need to create a new access sequence for Shipment Output determination including the Shipment Type, Shipping Point and Sold-To party.
    Can someone provide the steps involved to add the Sold-To party in the access sequence and the enhancement which I can use to populate the Sold-To party field.
    Thanks in advance for the help.
    Gajendra

    Murali,
    Thanks for your reponse. The way you suggested I have tried creating a new access table but the issue is Sold-To field is not available as a selection in the field catalog when you are in create access table screen (spro->Logistics Execution->Transportation->Basic Transportation Functions->Output Control-> Maintain Output Determination for Shipments->Maintain Condtion Tables->Maintain Output Condition Table for Shipments).
    When I go to the field catalog maintenance (spro->Logistics Execution->Transportation->Basic Transportation Functions->Output Control-> Maintain Output Determination for Shipments->Maintain Condtion Tables->Field catalog: Messages for transportation) the field KUNAG - Sold To Party does exist in the field catalog. However this doesn't show up on the access table maintenance screen as an available field.
    Could you please explain how to make this field available for access table maintenance?
    Regards,
    Gajendra

  • Why does apple allow apps in the App Store hijack your Internet when certain websites? Why doesn't apple remove their products from the App Store?.

    Why does apple allow apps in the App Store hijack your Internet when certain websites? Why doesn't apple remove their products from the App Store?.

    Apple saw it as their responsibility since the redirection took me to the App Store. They assisted me in stopping the redirection which is occurring on many peoples iPhones. It's a have java script problem that adking is using to get you to buy their games. The websites work normal and then all of the sudden the website is taken over by adking.com.  You can no longer use the website as it immediately takes you to the App Store without ever showing a popup to cancel the redirection. They were very helpful fixing the problem should others experiencing this specifically with adking.com.
    No need to get defensive. I'm not the only one experiencing the problem Apple said.

  • Why Java Web Start doesn't support Pack200 out-of-the-box?

    Hello All,
    Why Java Web Start doesn't support Pack200 out-of-the-box? I was hoping that Java 6 would make things easier by adding direct support for Pack200 in Java Web Start and JNLP without needing to use servlets, etc.? All my clients are Java 5 or above so I can't push the Pack200 compressed version of the jar to every single one of them and there is no selection process needed. But I can't do it because of the servlet or complex Apache server setup requirement (it would be a headache to get customers' web server admins to set up Apache or whatever web server that way).
    My question is why is there unwillingness to add Pack200 support directly to Java Web Start and JNLP so that you can start Pack200 compressed jars just like you would start any jar using Java Web Start? Is te a technical problem?
    Thank you,
    Mete Kural

    Hallo,
    I didn�t try it, but the webstart FAQ�s read:
    Can I use Pack200 compression with the JnlpDownloadServlet?
    Yes. The JnlpDownloadServlet distributed in the samples directory of the JDK now supports Pack200. If you deploy yourfile.jar along with yourfile.jar.pack.gz the packed file will be downloaded when the client is running Java Web Start 1.5.0 or later.
    http://java.sun.com/javase/6/docs/technotes/guides/javaws/developersguide/faq.html#217
    For further information you may want to look at
    http://java.sun.com/javase/6/docs/technotes/guides/javaws/developersguide/downloadservletguide.html#pack200
    The configuration of the server and the the servlet (as described in the second link) is as easy as it seems.
    I got it working on the first try and it was my first experience with websevers at all.
    Bye Schippe
    Message was edited by:
    Schippe

  • HT2341 why does my sound icon grey out and doesn't allow me to make changes on the system settings

    why does my sound icon grey out and doesn't allow me to make changes on the system settings

    When you go to System Preferences > Sound what does it say for Output? Have you had headphones plugged in? Sometimes the headphone jack gets stuck thinking it has something plugged in when there isn't anaything there. SMC also has something to do with Sound:
    SMC RESET
    http://support.apple.com/kb/HT3964
    Shut down the computer.
    Unplug the computer's power cord and ALL peripherals.
    Wait 15 seconds.
    Attach the computers power cable.
    Wait another 5 seconds and press the power button to turn on the computer.
    The 5 second timing is important to a successful reset.

Maybe you are looking for