"this" reference confusion

Hi
It is a basic doubt about the this.
As I run the test program here I expect the out put to be :
mainTESTMISC
SUPERMISC
TestMisc@19821f
TESTMISC
class SuperMisc {
     public String     SRC     = "SUPERMISC";
     public void log() {
          System.out.println(SRC);
          System.out.println(this);
          System.out.println(this.SRC);
public class TestMisc extends SuperMisc {
     public String     SRC     = "TESTMISC";
     public static void main(String... args) {
          TestMisc t = new TestMisc();
          System.out.println("main" + t.SRC);
          t.log();
but the output actually is
mainTESTMISC
SUPERMISC
TestMisc@19821f
SUPERMISC
Not that there is something wrong happening here but only that I am not able to understand that why the this.SRC is still getting the value of SRC in the super class. while "this" is the TestMisc object and TestMisc has a variable SRC in it.
Please help in making me understand the reason for this behavior.
Sapan

sapan wrote:
Hi EJP,
I do not want to get the output as I expect, But my question is about the reason why this is happening.
I just want to understand what I am missing in the behavior of the "this".
Sapan'this' always refer to the class variable (present class), and the reason the output is coming like you mentioned is because: you calling the super class method and in super class method the visible variable "SRC' value is SUPERMIC. And the super class method can never look /use the derived class variable.
Edited by: 833545 on Jul 26, 2012 6:09 PM

Similar Messages

  • Getting an enclosing class's this reference

    I'm creating a custom button and notifying registered ActionListeners whenever the button is clicked. In my code below, I want to create a new ActionEvent with the event source as "Button" instead of Button$Listener.
    From the Listener class, how can I obtain the parent's this reference? I've tried using Button.this, but when the listener calls getClass().getName() on the event, it says its an ActionEvent, not a Button. That also confuses me.
    public class Button extends JPanel
        private void notifyListeners(ActionEvent e)
            /* I could do it this way, but I'd rather not
            e.setSource(this);
            for ( ActionListener l : listeners )
                l.actionPerformed(e);
        private class Listener implements MouseListener
            public void mouseClicked(MouseEvent e)
                notifyListeners(new ActionEvent(this,
                                                ActionEvent.ACTION_PERFORMED,
                                                "clicked"));
    }

    I've tried using Button.this, but when the listener
    calls getClass().getName() on the event, it says its
    an ActionEvent, not a Button. Huh?
    public class Outer {
      public static void main(String[] args) throws Exception {
        Outer outer = new Outer();
        Outer.Inner inner = outer.new Inner();
        inner.foo();
      class Inner {
        void foo() {
          System.out.println(Outer.this.getClass().getName());
    prints "Outer"

  • I downloaded a song on iTunes, it won't play (it's name is grey), it shows up in purchased and says "play", but it won't play, I can't delete it, and I can't re-download it.....this is confusing please help!!

    I downloaded a song on iTunes, it won't play (it's name is grey), it shows up in purchased and says "play", but it won't play, I can't delete it, and I can't re-download it.....this is confusing please help!!

    Hello CTGame,
    Welcome to Apple Support Communities.
    It sounds like there’s a grayed out song in your iTunes library that can’t be played or downloaded again like other past purchases. Try taking a look at the article linked below and verify the computer is authorized to play that content.
    How to troubleshoot iTunes Match - Apple Support
    Songs appear to be missing
    Songs containing DRM (Digital Rights Management) might not appear in iCloud, or might appear grayed out. This can occur if your computer is not authorized to play that content. Try authorizing your computer, then manually update iTunes Match. To determine what Apple ID your computer needs to be authorized for to play a specific song:
    Locate and select the song in your iTunes library.
    Choose File > Get Info.
    In the Summary tab, locate the Account Name field in the right column. Write it down.
    Click OK.
    Choose Store > Authorize this Computer.
    Type in the account name from the Summary field and enter its password. Click Authorize.
    Choose Store > Update iTunes Match.
    So long,
    -Jason

  • HT6203 Did this update make a physical change? Branching from that question, will this update confuse lets say, a parent that isn't savvy?

    Did this update make a physical change? Branching from that question, will this update confuse lets say, a parent that isn't savvy?

    Did this update make a physical change?
    No
    will this update confuse lets say, a parent that isn't savvy?
    This will depend on whether they are savvy enough to open Macintosh HD > Applications > Utilities > AirPort Utility on their Mac , click on the picture of the AirPort, and then click the Update button.
    It that sounds too complicated, best to let someone else handle the update.

  • Pass "this" reference within SessionBean to other classes

    Can "this" reference for a SessionBean be passed to other helper classes?
    For example,
    public class MySb implements SessionBean {
    MyClass a = new MyClass();
    public void myBusinessMethod() {
    a.methodA(this);
    It looks strange that MyClass.methodA is expecting a SessionBean as opposed to a EJBObject interface as parameter. I also thought about passing the SessionContext object. Can someone tell me the pros and cons?
    Thank you.

    Thanks for the reply.
    There are disadvantages using the EJBObject directly. However, since the call always comes from the EJBObject instance and the helpers simply call its methods within the same method call. For performance reason, will it hurt to do that? i.e.
    public class MyStatefulSessionBean ... {
    public void methodA() {
    helperA.methodA(this, parms);
    void changeState(StateHelper helper){this.helper=helper;}
    class helperA {
    methodA(EJBObject obj, parms){
    obj.changeState(new HelperB);
    My other alternative is to pass the SessionContext to the helpers and helpers can call its getObject() to retrieve the remote interface. Then performance suffers and unwanted private method (changeState) has to be exposed to the public interface.

  • TS3772 this is confusing. i thought i just installed quicktime, but it says to install it. again?

    This is confusing. I thought I just installed QuickTime, but iTunes says to install it. Again?

    iCloud will still work for free, i.e sync your contacts between ios devices and the cloud (icloud.com) but for the calendar and addresses to sync with a windows PC you will need outlook 2007+.
    However as you dont use that part at the moment i'm sesning no great loss - icloud bookmarks and photo stream will sync with a windows pc without outlook so the rest of icloud will still work for you for free

  • I have an Iphone 4 iOS 6.1.3 and have read that it is capable to receive the Weather Emergency Alert system. I have also been told that it will not. This is confusing. Can someone at Apple clarify. If it doe not work on this phone is a download available?

    I have an Iphone 4 iOS 6.1.3 and have read that it is capable of receiving the Weather Emergency Alert system. I have also been told that it will not. There is no option in Settings / Notifications. This is confusing. Can someone at Apple clarify? If it does not work on this phone is a download available?

    Apple usually doesn't participate here, we're just users.  Have you done a search for an app for Weather Emergency Alert in the app store?  It certainly doesn't come built-in in the iphone.

  • I cant get my new iMac to talk to my Cannon mf4350d. Some chat sites say they never will.  My latest error message is: "No destinations have been added to the [Destinations List]"  I cannot find this reference in Help...

    I cant get my new iMac to talk to my Cannon mf4350d. Some chat sites say they never will.  My latest error message is: "No destinations have been added to the [Destinations List]"  I cannot find this reference in Help...

    I cant get my new iMac to talk to my Cannon mf4350d. Some chat sites say they never will.  My latest error message is: "No destinations have been added to the [Destinations List]"  I cannot find this reference in Help...

  • VI Server and "this" reference

    Hallo LabVIEWers,
    not a real problem (at the moment so far, but who knows ?). Is there a
    G-construct similar to the "this" reference in Java or C++, so that a VI can
    act on its own methods or property via the VI-Server. For example open
    reference to itself, modify some properties, call some methods, and close
    reference ?
    Best regards
    Oli

    Sure, place a property node or invoke mode on the block diagram and right
    click it. Select "Select VI Server Class >" and click on "VI". you can
    then select properties and methods for that VI. By not wiring a reference
    in, the node refers to the vi it resides in.
    Jared
    "Oliver Friedrich" wrote:
    >Hallo LabVIEWers,>>not a real problem (at the moment so far, but who knows
    ?). Is there a>G-construct similar to the "this" reference in Java or C++,
    so that a VI can>act on its own methods or property via the VI-Server. For
    example open>reference to itself, modify some properties, call some methods,
    and close>reference ?>>Best regards>>Oli>>

  • This reference

    I am curious to know which is faster. This is not critical by any means I am just curious.
    public void function(Object A){
    this.a = A;
    this.parse(a);
    this.convert(a);
    public void function(Object A){
    this.a = A;
    parse(a);
    convert(a);
    I am curious as to what mechanisms are used to locate the appropriate address space when using a this reference. Does the JVM store a shortcut table that it can use when you apply the this reference as opposed to a global list that is searches when the this reference is missing. I have no idea and would like any clarification available.
    James

    I am curious to know which is faster. This is not
    critical by any means I am just curious.
    public void function(Object A){
    this.a = A;
    this.parse(a);
    this.convert(a);
    public void function(Object A){
    this.a = A;
    parse(a);
    convert(a);
    I am curious as to what mechanisms are used to locate
    the appropriate address space when using a this
    reference. Does the JVM store a shortcut table that
    it can use when you apply the this reference as
    opposed to a global list that is searches when the
    this reference is missing. I have no idea and would
    like any clarification available.
    JamesThe .java file and the compiled bytecodes are two different things. The this keyword is implied. Explicitly putting the this keyword shouldn't make any difference to the compiler at all. I'm pretty sure that if you compile these two examples, the bytecodes are exactly the same. If I get a second I'll check unless someone else does it first.

  • Hi I buying a secondhand I mac 2007 snow leopard 10.6.3 will I be able to upgrade this ? Confused as need to this

    Hi I buying a secondhand I mac 2007 snow leopard 10.6.3 will I be able to upgrade this ? Confused as new to this thanks

    You should certainly update it to 10.6.8 via software update. As for for upgrading, it depends on what Mac it is.
    When you have installed it, run Software Update to download and install the latest updates for Snow Leopard to bring it up to 10.6.8, or download the combo update from here:
    http://support.apple.com/kb/DL1399
    Check via Software Update whether further updates are required.
    You should now see the App Store icon in iTunes, and you now need to set up your account:
    http://support.apple.com/kb/HT4479
    To use iCloud you have to upgrade at least to Lion, but some functions are only available in Mountain Lion:
    http://support.apple.com/kb/HT4759
    You can also purchase the code to use to download Lion (Lion requires an Intel-based Mac with a Core 2 Duo, i3, i5, i7 or Xeon processor and 2GB of RAM, running the latest version of Snow Leopard), or you can purchase Mountain Lion from the App Store - if you can run that:
    http://www.apple.com/osx/specs/

  • Reference confusion....

    <sigh>......I thought I was being clever here, but apparently not. :)
    I had two methods that, apart from the List result variable and the String SQL were exactly the same, so I thought I'd write a general method (getResultList) that would do both in one, so to speak and just pass the result object references as parameters to the method. The method works, but the reference variables are still null when I try and use them.....specifically I get a NullPointerException.
    Here is the code.......my thinking must be faulty here, because the two Lists (listBasePatientDetails and listNormalPatientIDs) which hold the results are null when I try and use them after calling loadData().
    private OracleDataConnection theConnection;
    private List listNormalPatientIDs;
    private List listBasePatientDetails;
    private boolean loadData() {
            if (getNormalPatientIDs() == false || getBasePatientDetails() == false) {
                return false;
            } else {
                return true;
        private boolean getNormalPatientIDs() {
            String sqlString = "SELECT PATID_REFNO FROM PATIENT_IDS";
            if (!getResultList(sqlString, listNormalPatientIDs)) {
                ErrorList.addError(new ErrorItem(ErrorList.DATABASE_QUERY_FAILED, 0, "RPatientID::getNormalPatientIDs()", "Could not retrieve normal patient IDs. Database query failed"));
                return false;
            } else {
                return true;
        private boolean getBasePatientDetails() {
            String sqlString = "SELECT PATID_REFNO, PITYP_REFNO, PATNT_REFNO, IDENTIFIER FROM PATIENT_IDS";
            if (!getResultList(sqlString, listBasePatientDetails)) {
                ErrorList.addError(new ErrorItem(ErrorList.DATABASE_QUERY_FAILED, 0, "RPatientID::getBasePatientDetails()", "Could not retrieve base patient details. Database query failed"));
                return false;
            } else {
                return true;
        private boolean getResultList(String sSQL, List returnList) {
            List resultList;
            if (theConnection.hasConnection()) {
                resultList = (List)theConnection.executeSQL(sSQL);
                if (resultList == null) {
                    return false;
                } else {
                    returnList = resultList;
                    return true;
            } else {
                // Lost database connection.
                ErrorList.addError(new ErrorItem(ErrorList.DATABASE_CONNECTION_FAILED, 0, "RPatientID::getResultList", "Could not retrieve query data. Database connection lost."));
                return false;
        }So whats going wrong here? Is the result List reference used as a parameter going out of scope or something after returning from getResultList? I must have some gap in my thinking, because I thought references were pretty similar to pointers......ie. they just point to the objects rather than hold the objects themselves.
    Suggestions? Thanks all.

    public class ReturnTest {
      private static String s = "hio";
      public static boolean stuff(String str) {
        str = "YAHOOOOoooOOO";
        return false;
      public static void main(String[] args) {
        System.out.println(s);
        stuff(s);
        System.out.println(s);
    }Try compiling that. When you run it you will notice that s still prints out as "hio." This is basically what you are doing with your method.
    The parameter "str" (or returnList in your case) has a different address (pointer) than the original s. This is because Java makes copies of all the objects you pass to methods as paramters. To make your method work, you're either going to have to modify your two private lists directly or do something along the lines of this:
    public class ReturnTest {
      private static String s = "hio";
      public static boolean stuff(String str) {
        str = "YAHOOOOoooOOO";
        s = str;
        return false;
      public static void main(String[] args) {
        System.out.println(s);
        stuff(s);
        System.out.println(s);
    }Note how I put "s = str;" in the stuff() method. If you were to run this, you would see the output:
    hio
    YAHOOOOoooOOO
    Like I said, there's probably a better way to do this, but that's my solution to your predicament.

  • Could not resolve this reference. Could not locate the assembly "MySql.Data, Version=6.8.3.0

    I am getting the subject error message when I try to compile, using VS, a VB Forms app which I had been developing on a desktop machine but which I am now developing on a laptop.  I am using exactly the same VS files as they are in Dropbox.  (And
    incidentally I no longer have access to the desktop machine.)
    The subject error message points to:  Imports MySql.Data.MySqlClient
    I have been down this path before and can usually, eventually, resolve it by installing something and then creating a reference to the right dll.  For me that's an iterative process as it's not always obvious, to me, what I need to install and which
    file needs to be referenced.  
    But the only help I am seeking from this groups is:  What makes VS think that it needs "Version=6.8.3.0"?  I am pretty certain that I never told it that it needed that version.  And how can I change its mind so that it will compile
    using a different version? 
    I keep telling it to use 
    ... but it doesn't like it and I don't know if the problem is that it's the wrong version or if the problem is that it doesn't contain the right stuff.
    Thanks for whatever guidance anyone can offer.
    Thanks,  Bob

    The version shown here does not say that this is the version that is required, it indicates the version of the assembly that was referenced.
    What will determine the version that is required, or if a specific version is required, will be the properties that you set on the reference, which can be viewed by clicking on the reference in Visual Studio and setting "Specific Version" to true
    or false, the software in question and if the signatures match up to what you are binding to.
    Now, for your specific issue, I tend to add a NuGet reference for SQLite and it makes updating versions, and maintaining specific version requirements, much nicer than using a globally installed version of the SQLite libraries.
    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.
    Thank you very much TSoftware.  Especially for telling me about "Specific Version" - I changed that to false and they the app compiled.  Thanks very much.  Bob

  • HT1338 My computer will run on 10.5 and is currently on 10.4.11. Where can I obtain this reference release? 10.6 is beyond the spec of the machine.

    I have inherited a 2005 IMAC G5 which will run on 10.5 Leopard but not 10.6 Snow Leopard. For my purposes it is still a serviceable bit of kit but it runs on 10.4.11 presently. I have upgraded the memory to 2.5GB but cannot seem to locate a copy of 10.5 anywhere. Does anyone know where I can obtain a legitimate reference upgrade from? Many thanks.

    Leopard is no longer available at the Apple Store but may be available by calling Apple Phone Sales @ 1-800-MY-APPLE (1-800-692-7753).
    If you can't obtain a retail install DVD from Apple, look on eBay or Google the installer part numbers to possibly find at an on-line store. Here's what to look for:
    MB427Z/A  Leopard 10.5.1 install DVD
    MB576Z/A  Leopard 10.5.4 install DVD
    MB021Z/A  Leopard 10.5.6 install DVD (single user)
    MB022Z/A  Leopard 10.5.6 install DVD (5-user family pack)
    Installing Mac OS X 10.5 Leopard
    http://support.apple.com/kb/HT1544
    Mac OS X 10.5 Leopard Installation and Setup Guide
    http://manuals.info.apple.com/en/leopard_install-setup.pdf
    After you install the base 10.5, download & install the 10.5.8 combo update at http://support.apple.com/downloads/Mac_OS_X_10_5_8_Combo_Update
    The DVD should look like this
    Caution - Leopard does not support classic mode. So, if you currently open OS 9 apps in classic mode, you won't be able to do this if you upgrade to Leopard.
     Cheers, Tom

  • How do i sync pages from iMac to iPad. I am new to mac and this is confusing

    how do I sync between IMAC and IPAD. I just downloaded pages into my IMAC and I can not figure out how to download it onto my ipad2. I do not want to download the product again for $10. i was told that this is handled in itunes but i can not figure it out

    You got some bad information if you think that you do not have to buy Pages for the iPad and you think that it will work without it.
    You have to purchase Pages for the iPad as well as for the Mac. You cannot install any computer program on an iPad - Mac or Windows applications will not work on the iPad. You will have to download and install the iPad Pages app or you cant sync files from the Mac to the iPad and the other way around.

Maybe you are looking for

  • Unable to scan and communicat​e with scan function C6180 Vista Home Premium 64 bit Printing works

    I have an all in one C6180 Photosmart connected by wireless network (infrastructure). Network consists of 2-laptops, 1-Desktop and the printer.  Everything works from HP solution Center on the Compaq laptop and the Dell desktop both running Windows X

  • Vmotion redundancy across subnets.

    Hi, I'm fairly new to the UCS/VMWare world.  Another tech in my department who is mainly responsible for our VM infrastructure is doing some work with Vmotion and trying to set up some high availability failover for our VM's. What we'd like to do is

  • Screens missing when the Recording is processed : XK01

    I need to upload vendor master data. I also need to capture second address under the International Versions section. I could record it ( selecting the checkbox "Not a Batch Input Session") in the very first screen of SHDB. Otherwise we will not be ab

  • Help swf loader

    Hello all, I use Flash CS4 with AS3. I have a problem with the site preloader. When I  simulate the loading it is "invisible" for a while and then show up  starting loading from ~ 24-27% or maybe ~55% To resolve  this some people suggested me to crea

  • Podcast Moved to Another Sever - links broken

    My podcasts had to be moved to another server because lack of bandwitdth. I changed the URL in the RSS file - do I need to resubmit? Even when I test the URL from within iTunes it will download. The server does not start with an "http://www." prefix,