Why are all methods virtual???

class Base
     public Base()
          System.out.println("Calling f() from base class ...");
          f();
          return;
     public void f()
          System.out.println("Base class function called!");
          return;
class Derived extends Base
     public Derived()
          System.out.println("Calling f() from derived class ...");
          f();
          return;
     public void f()
          System.out.println("Derived class function called!");
          return;
     public static void main(String args[])
          new Derived();
          return;
}The problem in this: the call to f() from the Base class calls the Derived class method. I want it to call the Base class method. How do I do this?
Ravi

Sorry, I cant explain the circumstances under which I
encountered this problem without explaining a whole
lot about my product. But I cant make it a private
method because I need to be able to call it from
outside the package. I found a workaround for my
problem by putting a call to super.f() in the derived
class. But I really wonder why the makers of Java
chose to make it this way!
RaviIf you can't explain your problem then don't post your questions here. It's not like a small post on a forum board will cause your IP any damage.
The design of OOP is that if you override a method in a subclass of an object, the reason for doing so is that you are add/changing functionality of that method. If you don't need to add/change functionality of a method then don't override it. Polymorphism ensures that no matter what type of object the compiler thinks you are reffering to, at runtime you will call the correct method of the type of object you encounter then. This is why interfaces work. calling the super class to complete processing of a method is not a hack, or a design problem it's the way to do it. If the class that you are extending changes private data structures in a method, and you override that method, unless you are doing a radical change to the class, you probably need to call the super method to ensure that the proper changes are made.

Similar Messages

  • Why are all my movies and tv shows now on my ipad with the icloud icon?  How can i get rid of them?

    Why are all my movies and tv shows from my library now on my ipad with the icloud icon?  I have turned off all icloud related services. I have never used it.  On top of that, my ipad now gets stuck on step 5 of the sync - waiting for changes to be applied and never finishes.
    Help

    Hi, go in Settings, under Videos turn off "Show all videos"  this will remove the purchased videos to be displayed in the Video app.  The same can be done with the music.
    As for Step 5, connect you iPad and on the summary Tab, uncheck
    "Sync only checked songs and videos".  Then wait, it takes a while but this made it work for me after many restore attempts.
    good luck

  • Why are all my pictures not on my ipad

    Why are all my photos from my phone not on my iPad?

    Very vague.
    Did you put them there?

  • Why are all paths in Clipping Masks and Compound Paths?

    When I open up previous versions of Illustrator files (i.e. CS5), why are all of my paths messed up. Every object is embedded in a Clipping Mask, paths are compounded and in most cases type on a path is expanded into multiple non-editable objects. This causes complete redesign. This is terrible.

    Because Illustrator accessed the PDF part of the file.
    ---> this points to corrupt files.
    How were those files transferred to your computer? Are they on a server?
    How old are they?
    Which versions were they created in?
    Did you already try to restart (the computer)?
    Any plugins installed?

  • In iTunes under my device, under the apps tab, Why are all the options shaded out?  I cannot make any changes, select any apps or do anything with the apps.  I was able to load a few apps and sync but cannot sync anymore to my phone.

    In iTunes under my device, under the apps tab, Why are all the options shaded out?  I cannot make any changes, select any apps or do anything with the apps.  I was able to load a few apps and sync but cannot sync anymore to my phone.

    Hi,
    ( I search for iChat questions when I have finished in the iChat Forum)
    So the menu bar reads iChat, File,  Edit,  View, Buddies, Video, Window and Help
    There is no Buddy List open.
    There is no other window for iChat open.
    In the iChat Menu you only have access to Status.
    Is an item ticked in the list ?
    Is this a green (Available item) or  Red ( an Away one) ?
    Can you access the Accounts option ?  (Sitll in the iChat Menu)
    Is anything in here ticked ?
    In the Window menu any Logged in account should appear in the list  (Between the Next Chat and File Transfer items)
    It would be useful to know which version of iChat this is.
    If no account is ticked (iChat Menu > Accounts) or not showing in the Window Menu, plus you cannot determine the Status and you cannot access the Preferences then you need to access your Home Folder/Library/Preferences
    As the Library in the Home Holder is Invisible in Lion you will need the Finder's Go Menu > Go to Folder option  (you can use it in earlier OS versions if you want)
    Type in:-
    ~/Library/Preferences
    Find the file called com.apple.ichat.plist
    Drag it to the Trash and Restart iChat.
    This will lose all the settings in iChat that you have changed from Defaults but there is no way around this.
    9:23 PM      Saturday; August 27, 2011
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb( 10.6.8)
     Mac OS X (10.6.8),
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • Why are all of my file icons appearing to be PDF files?

    Why are  All my icon for folders programs are adobe icons.I click on any I get the adobe page (linternet explorer, chrome program files)
    Message was edited by: rapid7121

    See http://helpx.adobe.com/acrobat/kb/application-file-icons-change-acrobat.html

  • HT5557 Why are all my books that I have purchased no longer in my library?

    Why are all my books that I have purchased no longer in my library?

    The problem is, if I'm in an area that I don't have service or Wi-Fi and I want to read a book that I have purchased and paid for and I can't retrieve it...it is extremely annoying. I have paid A LOT of money for MANY MANY ebooks.  I HAVE NOT DOWNLOADED THE NEW 7.0 SYSTEM BECAUSE I DO NOT LIKE IT. I HAVE IT ON MY IPHONE AND IT HAS TOTALLY SCREWED UP MY CALENDAR AND A FEW OTHER APPS.  I DID NOT WANT THE CHANGES ON THE IPAD TOO.  In other words, I have done nothing different.  My Kindle app is working great and has twice to five times more e-books in it.  The sad part is that iBooks charges more and does not get the new releases out as well and timely as Amazon.  I use Amazon more often now but I do like to keep my series together and for that reason I of still use them occasionally. 

  • Why are all my contacts suddenly 2 hours earlier than they were entered.  I just noticed this today April 24

    Why are all my entries on Icloud 2 hours earlier than they were previously entered.  I just noticed this today April 23?  They do not match what is on my Ipad or on my imac.  Looks like the clocks are not syncronised someplace.

    Your post is fascinating because your post header says "today April 24" while your post body says "today April 23"   So maybe that is related...
    Anyway, make sure all your iCloud devices have Settings > General > Date & Time > Set Automatically = "On".
    Also, in iCloud.com, open Calendar, go to Preferences (upper right) > Advanced > and check "Enable Time Zone Support".

  • Why are all of my contacts duplicated on my iPhone/ipad with iCloud?

    Why are all of my contacts duplicated on my iphone and ipad when using icloud?

    One way this happens is when you previously synced contacts via iTunes/USB cable.  If you haven't turned that off in iTunes, then you'll get duplicates from iTunes and iCloud.

  • Why are all disks being ejected from my MacBook Pro?

    Why are all disks being ejected from my MacBook Pro?

    Likely that your optical drive is either failing or has a dirty laser lens and cannot read the disks.....

  • HT3726 why are all of the templates in Spanish?

    Why are all the templates and text in Spanish on Pages

    It is Latin nonsense, placeholder text to show the layout. Click in a text box and start typing. Your text will replace it.
    Regards,
    Ian.

  • Why are all urls coming up invalid when I am connected to my wireless network?

    Why are all urls coming up invalid when I am connected to my wireless network?

    First back up the registry
    Go to Start > Run --> type in regedit and hit OK. 
    Navigate to the key HKEY_CURRENT_USER\Software\Classes\LocalSettings\Software\Microsoft\Windows\CurrentVersion\TrayNotify. 
    Delete the values IconStreams and PastIconsStream. 
    Open up the Task Manager, go to the Processes tab, select explorer.exe and click End
    Process. 
    Open the Applications tab and click New Task at the bottom-right of the window. 
    In the message box that pops up type in explorer.exe and hit OK. 
    Explorer.exe will reload, and the missing icons should now be back in the system-tray
    where they belong. 

  • Why are all of our cords breaking, so we can not charge anything?

    Why are all of the cords so cheap, and breaking?

    I am pretty certain that Apple put something into iOS 6.1.4 to REJECT all 3rd-party power cords.  Ever since I updated to iOS 6.1.4, my most trusted cord (4 months old) has been saying, "You cannot charge the device with this cord".  BZZZT Apple strikes again !!
    Either that, or the new "Kill your battery as quickly as possible" software in iOS 6.1.4 has been draining power so rapidly, that my 3rd-party cord cannot keep up with the massive power-draw from iOS 6.1.4 !!  Don't upgrade !!

  • HT4539 Why are all these apps only available for everything but my MacBook Pro?

    Why are all apps only available for phones or pads??I only want to use them on my MacBook Pro???

    Itunes does not sell any apps at all for computers.
    Itunes ONLY sells apps for iphone/ipod/ipad.
    If you want an app for your Mac, tehn shop in th Mac App Store

  • Why are all my apps 32-bit on a Windows 8.1 desktop with 12GB RAM?

    Why are all my CC 2014 apps on a Windows 8.1 desktop with 12GB RAM 32-bit instead of 64-bit? 
    Thanks

    >don't see anything there regarding 64-bit applications
    You need to click on EACH program to read the requirements for THAT program
    System requirements | After Effects- Intel Core2 Duo or AMD Phenom II processor with 64-bit support
    System requirements | Adobe Premiere Pro- Intel Core2 Duo or AMD Phenom II processor with 64-bit support
    And so on... if the INDIVIDUAL page does say 64bit the program does not REQUIRE 64bit

Maybe you are looking for