How the compiler chooses which method to invoke?

  public class A {
        public void foo(Object o) {
            System.out.println("A.foo with an object");
  public class B extends A {
        public void foo(Object o) {
            System.out.println("B.foo with an object");   
        public void foo(String s) {
            System.out.println("B.foo with a string");   
public class C {
    public static void main(String[] args) {
        String s = "hello";
        A a = new B();
        a.foo(s);
}why the output is "B.foo with an object" and not "B.foo with a String".
or more generally: how the compiler choses the method to invoke?

or more generally: how the compiler choses the method
to invoke?Variable a is declared as a reference to an A. The compiler only knows this. It doesn't know that the object it happens to be pointing at is a B. So it only looks at A's methods.
A has only foo(Object), so it will call the method with the signature foo(Object).
Which signature to use is determined at compile time, and is determined by the type of the reference.
Now, as for whether A's foo or B's foo, that's where Java's polymorphism comes in. In this case, the VM looks at the object, not the reference, and calls the "deepest" (furthest from Object) class' method that matches that signature.
Which class' implementation of that signature to call is determined at runtime, and is determined by the object, not the reference.

Similar Messages

  • Several contacts have the same email address. How can I choose which contact name appears on the address line in Mail?

    Several contacts have the same email address. How can I choose which contact name appears on the address line in Mail?

    you can't really, but you might be able to filter them by message content into folders for each, or color them with tags

  • When sending from a mobile app, how can I choose which of my computers to open the document on?

    I have a laptop and a desktop computer connected to creative cloud. How can I choose which machine to open up a document from my iOS app? I don't want it to open on both overtime I send something from my iOS device.

    The Cloud forum is not about using individual programs
    The Cloud forum is about the Cloud as a delivery & install process
    If you will start at the Forums Index https://forums.adobe.com/welcome
    You will be able to select a forum for the specific Adobe product(s) you use
    Click the "down arrow" symbol on the right (where it says All communities) to open the drop down list and scroll

  • How do I choose which items appear when I open my Imac for the day?

    How do I choose which items appear on the screen when I open my Imac (intel) for the day, after shutting down the night before? Thank you. ArmandL

    There are two ways. Mt Lion and Lion have a feature that launches all programs that were running when you logged out or shut down. You can toggle this feature on and off when you shutdown/log out. Or you can set up login items in your user settings which will automatically launch any program you set there. To do this launch System Preferences, select Users and Groups and click on the Login Items but near the top part of the dialog. Click on the + button to add programs you want to be launched when you login or start up the computer.

  • How does ISE choose which IP to put in URL redirect response?

    Hello,
    does anyone know how does ISE choose which IP to put in URL redirect response if it has more than one interface with an IP address and all interfaces are enabled in the portal configuration?
    I have a single ISE 1.3 PSN with all four interfaces configured, enabled, each on unique VLAN, and each with unique IP address.
    In the CWA portal configuration, all four interfaces are enabled.
    Wired clients connect to NAD, NAD sends RADIUS request to ISE, ISE responds with a RADIUS response including the URL-Redirect parameter which specifies the web redirect URL. ISE configuration uses "ip:port" in the URL. 
    My question is how does ISE choose which of its four interfaces to put in this URL? Is it always the same interface that RADIUS packets were received on? Or does it always choose the first portal enabled interface? Or is there another logic? Configurable or unconfigurable?
    Thanks!

    ISE uses the first interface enabled for that portal, so if want to use a specific interface, then only enable that interface.  If interface is GE0, then default behavior is to redirect with ip value set to node's FQDN.  If interface other than GE0, then default behavior is to return the IP address of the associated interface. 
    Aliases can be configured for each interface using the CLI 'ip host' command to associate a hostname/FQDN to the IP address of a given interface.  When configured, ISE will return that value rather than IP address in redirect.  This is critical if want to avoid certificate trust warning on connecting clients.
    Be sure that certificate assigned to interface includes the correct FQDN or optionally wilcard value in the CN or SAN fields to avoid cert warnings.

  • When I delete a duplicate song, how do I choose which file to keep?

    When I delete a duplicate song, how do I choose which file to keep?

    What is reappearing is just the list entry with the indication that it is available for download - it's not taking up any space on your computer. You can remove it by control- or right-clicking it and choosing 'delete'.
    The recent changes in iTunes have confused a lot of people. Here is a summary of the situation:
    Only the most recent episode shows when you first subscribe. In the default  'My Podcasts' view click 'Old episodes' to show earlier episodes, click 'Done' to hide them or 'Add all' to keep them there and also add them to List view.
    Alternatively, in 'List' view control- or right-click on the name of the podcast or the episode and choose 'Show old episodes' to reveal all the previous episodes.
    In both views you can now delete both downloaded or un-downloaded episodes from both views by control- or right-clicking on the name of the episode.
    In both views each episode now has a blue circle to the left showing it as unplayed. Each episode can be double-clicked to be played as a stream without downloading it first (so you don't have to wait for it to download fully). Click the cloud icon at right to download it (as you will have to to sync it to an iPod). Note that if you click the cloud icon to the right of the title of the podcast itself, rather than an episode, you will initiate a download of all episodes.

  • How do I choose which programme files open in?

    Before I upgraded to Snow Leopard I could double clic on an image in Quark and it would open in the programme that created it (eg photoshop or illustrator) in order to amend or change.
    Now when I do that everything opens in Preview - how do I choose which programme files open in?

    You can right click on a file icon to open a contextual menu to pick an "open with" option.
    You can change the default open with app via the Get Info window in Finder. It also has a "change all" option that will open all of the same file extensions using the app of your choice.

  • How the system know which are Inventory cubes?while compres in ProcessChain

    Hi,Experts
    When I create a Cube compress in ProcessChain ,under the page there is a checkbox called No Maker for Inventory Cube,and I also know the Non-cumulative key figure can not be compress,
    My question is how the system know which are Inventory cubes? and many cube create from ourself.

    Hi,
    I think,
    - in the sap tables there are no information.
    - the program reads the infocube definition and check: is there a non-***. value?
    Sven

  • How do you choose which photos from Aperture for Apple TV screen saver?

    How do you choose which photos from Aperture for Apple TV screen saver?

    How do you choose which photos from Aperture for Apple TV screen saver?

  • How to compile package which contain class outside the package

    I am writing a JDBC driver.
    I have the following package structure in the folder:
    MyDriver
        |_manager.jar
        |_com
               |_ jdbc
                       |_ HXDriver
                       |_ HXConnection
                       |_ HXResultSet
                       |_ HXStatementIn manager.jar, there is a remote object Interaface(Manager.java) which I need to use inside HXConnection.
    My question is how to compile(or/and how to set the classpath)so that I can compile the 4 classes inside jdbc package.
    I tried this:
    C:\MyDriver>javac -cp .;manager.jar com/hx/jdbc/*.java
    However, this does not work, compiler says it cannot find Manager
    Please help me.
    Cheers

    D:\380 Project\Driver>javac -cp .;manager.jar com\hx\jdbc\*.java
    com\hx\jdbc\HXConnection.java:21: cannot find symbol
    symbol  : class Manager
    location: class com.hx.jdbc.HXConnection
            private Manager manager;
                    ^
    com\hx\jdbc\HXStatement.java:18: cannot find symbol
    symbol  : class Manager
    location: class com.hx.jdbc.HXStatement
            private Manager manager;
                    ^
    com\hx\jdbc\HXStatement.java:20: cannot find symbol
    symbol  : class Manager
    location: class com.hx.jdbc.HXStatement
            public HXStatement(Manager manager){
                               ^
    com\hx\jdbc\HXConnection.java:41: cannot find symbol
    symbol  : class Manager
    location: class com.hx.jdbc.HXConnection
                            manager = (Manager)reg.lookup("manager");
                                       ^

  • When using Multicam in CS6 how do I choose which source file the audio comes from?

    I've noticed when using the Multi-cam window to create edits, the audio does not change when I select the different video sources. How do I select which source file the audio comes from?

    It doesn't make sense why the multicam source sequence only uses one track of audio. Was this by design? The issue with this as in my situation (and because I didn't know this) I recorded all my source videos with the music tracks on the right side which is what I'm using to cut my video with. Not being able to hear this while I'm cutting is really frustrating. There's a reason I separate dialog on the left side and music on the right. There should at a minimum be an option while setting up the multicam to choose more audio options. Even in the audio clip option settings, those don't seem to work when a clip is put into a multicam source sequence.
    The other issue is when you bring in the audio after the fact or even before, there's no way to sync timecode with audio to the multicam sequence. When I create the Multicam source sequences in my project bin, I choose sync with timecode, not in points, because the record decks I'm using are all locked with a TC gen during the shoot.
    Maybe I'm missing something, but there seems to be either a bug with multicam or a design flaw. Even in the help documentation, it states multiple audio tracks can be brought in with the multicam sequence, but only track one is enabled by default. I've never been able to have the MC sequence bring in more than one track of audio no matter what the audio settings are.

  • How do they choose which ebook to put on the featured list

    My book is up on iTunes. It is very high quality. Howl do they choose which ones to have on the Featured list as opposed to merely the release date category.  Also... What about DRM.? What's the difference and does this accept their decision?

    ISE uses the first interface enabled for that portal, so if want to use a specific interface, then only enable that interface.  If interface is GE0, then default behavior is to redirect with ip value set to node's FQDN.  If interface other than GE0, then default behavior is to return the IP address of the associated interface. 
    Aliases can be configured for each interface using the CLI 'ip host' command to associate a hostname/FQDN to the IP address of a given interface.  When configured, ISE will return that value rather than IP address in redirect.  This is critical if want to avoid certificate trust warning on connecting clients.
    Be sure that certificate assigned to interface includes the correct FQDN or optionally wilcard value in the CN or SAN fields to avoid cert warnings.

  • How to dynamically choose which view to display in second step

    Hi Guys,
    I am just started to evaluate fpm to decide whether to use it in our project. So i have question that might be very simple to you all, that i hope you all can help me with.
    Say i want to use the fpm GAF with a single webdynpro component. I have 3 steps, first step display a dropdown list for user to choose, second step will be a view that will depend on user input on the first step and 3rd step just a confirmation screen.
    I plan to use UIBB for all the screen, not using the GUIBB. So i will need to dynamically decide which view to show on step 2, and since we don't call navigation plug when we use fpm, what is the best way to archive this? How do i design my webdynpro component and the fpm configuration etc...?
    I read from the programming guide about initial screen and variant. But what if my application doesn't need an initial screen and the user choosing step is not at the first step, I can't use variant in this case right?
    thanks.

    Hi
    You can give the dropdown on initial screen and than u can decide which screen  to show on the second (or infact that will we the first step you you have first step as a initial screen.
    How?? :
    1. Create different varients for the second step.
    2. Basis on the Value choosen in the dropdown list, select the appropriate varient using the following code.
      TRY.
            CALL METHOD io_gaf->set_variant
              EXPORTING
                iv_variant_id = 'VAR_CLIENT'.
          CATCH cx_fpm_floorplan .
        ENDTRY.     
    where  VAR_CLIENT  is your varient.
    Hope this will help you.
    Thanks & Regards,
    Arvind

  • How do I choose which version of Acrobat will be updated?

    I have a Mac Pro with one hard drive dedicated to nightly clone backups of my main drive. When the Adobe Acrobat Updater tells me that an update "to version 11.0.02 is available. Do you want to install it now?" How can know and/or choose which version it will update?
    Because the cloned backups are stable in their environments, I only want to update the one on my main drive.
    Thank you.

    Help > About Firefox
    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.18) Gecko/20110614 Firefox/3.6.18 ( ) = '''3.6.18''' - but that '''( )''' doesn't belong there and Quickbooks Online might be misreading your UserAgent as a result of that ( ) being there.
    Try resetting your UserAgent string.<br />
    [http://en.wikipedia.org/wiki/User_Agent]
    type '''about:config''' in the URL bar and hit Enter <br />
    ''If you see the warning, you can confirm that you want to access that page.'' <br />
    Filter = '''general.useragent.''' <br />
    Right-click the preferences that are '''bold''', one line at a time, and select '''''Reset'''''. <br />
    Then restart Firefox

  • How do I choose which drive to install adobe programs to?

    I just bought a new SSD for my computer and want to install my adobe programs to it but I can't find the option to choose which drive I want to install it to.

    Finder is going to have to start at each bootup. It's how you interact with Mac OS X.
    Follow Keppy's instructions above if you have other programs that you want to load at start up.

Maybe you are looking for